Python Fundamental || Type B || Sumita Arora || Class 11 || Computer science || Information practices || Solution


Q1. From the following, find out which assignment statement will produce an error. State reason(s) too.

(a) x = 55
(b) y = 037
(c) z = 0o98
(d) 56thnumber = 3300
(e) length = 450.17
(f) !Taylor = 'Instant'
(g) this variable = 87.E02
(h) float = .17E - 03
(i) FLOAT = 0.17E - 03



Q2. How will Python evaluate the following expression?

(i) 20 + 30 * 40
(ii) 20 - 30 + 40
(iii) (20 + 30) * 40
(iv) 15.0 / 4 + (8 + 3.0)




Q3. Find out the error(s) in following code fragments:

(i)
temperature = 90
print temperature

(ii)
a = 30
b= a + b
print (a And b)

(iii)
a, b, c = 2, 8, 9
print (a, b, c)
c, b, a = a, b, c
print (a; b; c)

(iv)
X = 24
4 = X

(v) print ("X="X)

(vi)
else = 21 - 5





Q4. What will be the output produced by following code fragment (s)?

(i)
X = 10
X = X + 10
X = X - 5
print (X)
X, Y = X- 2, 22
print (X, Y)

(ii)
first = 2
second = 3
third = first + second
print (first, second, third)
first = first + second + third
third = second * first
print (first, second, third)

(iii)
side = int(input('side')) #side given as 7
area = side * side
print (side, area)





Q5. What is the problem with the following fragments?

(i)
a = 3
         print (a)
b = 4
         print (b)
s = a + b
        print (s)

(ii)
name = "Prejith"
age = 26
print ("Your name & age are", name + age)

(iii)
a = 3
s = a + 18
a = "New"
q = a / 10





Q6. Predict the output:

(a)
x = 40
y = x + 1
x = 20, y + x
print (x, y)



(b)
x, y = 20, 60
y, x, y = x, y - 10, x + 18
print (x, y)



(c)
a, b = 12, 13
c, b = a * 2, a / 2
print (a, b, c)

(d)
a, b= 12, 13
print (print(a + b))



Q7. Predict the output

a, b, c = 10, 20, 30
p, q, r = c-5, a +3, b - 4
print ('a, b, c :', a, b, c, end = '')
print ('p, q, r : ', p, q, r)





Q8. Find the errors in following code fragment:

(a)
Y = x + 5
print (x, Y)

(b)
print (x = y = 5)

(c)
a = input ('value')
b = a / 2
print (a, b)





Q9. Find the errors in following code fragment: (The input entered is XI)

c = int(input("Enter your class "))
print ("Your class is", c)





Q10. Consider the following code:

name = input('What is your name? ')
print ('Hi', name, ',')
print ('How are you doing? ')

was intended to print output as

Hi <name>, How are you doing?

But it is printing the output as:

Hi <name>,
How are you doing?

What could be the problem? Can you suggest the solution for the same?





Q11. Find the errors in following code fragment:

c = input( "Enter your class")
print ("Last year you were in class") c-1





Q12. What will be returned by Python as result of following statements?

(a)
>>> type(0)

(b)
>>>type(int(0))

(c)
>>>.type(int('0'))

(d)
>>> type('0')

(e)
>>>type(1.0)

(f)
>>>type(int(1.0))

(g)
>>>type(float(0))

(h)
>>>type(float(1.0))

(i)
>>>type(3/2)

Match your result after executing above statements.





Q13. What will be the output produced by following code?

(a)
>>> str(print()) + "One"

(b)
 >>> str(print("hello")) + "One"



(c)
>>> print(print("Hola"))

(d)
>>>print(print ("Hola", end = ""))

Match your result after executing above statements. Can you explain why this result came?





Q14. Carefully look at the following code and its execution on Python shell. Why is the last assignment giving error?

>>> a = 0o12
>>>print(a)
10
>>> b = 0o13
>>> c = 0o78
File "<python-input-41-27fbe2fd265f>", line 1
0078
Syntax Error: invalid syntax




Q15. Predict the output:

a, b, c = 2, 3, 4
a, b, c = a * a, a * b, a * c
print(a, b, c) 




Q16. The id() can be used to get the memory address of a variable Consider the following code and tell if the id () functions

will return the same value or not (as the value to be printed via print()) ? Why?
[There are four print() function statements that are printing id of variable num below)

num = 13
print(id(num))#1
num = num +3
print( id(num) )#2
num = num - 3
print( id(num))#3
num="Hello"
print(id(num))#4





Q17. Consider below given two sets of codes, which are nearly identical, along with their execution in Python shell Notice

that first code fragment after taking input gives error, while second code-fragment not produce error. Can you tell why?

>>> print(num = float(input("value:")) )
value:67
Traceback (most recent call last):
File "ipython-input-56-78b83d911bc6>", line 1, in <modules
print(num= float (input("value:")))

Type Error: 'num is an invalid keyword argument for this function

>>>print(float(input("value1 :")))

value1:67
67.0




Q18. Predict the output of the following code:

days = int (input("Input days: ")) * 3600 * 24
hours = int (input("Input hours: ")) * 3600
minutes = int (input("Input minutes: ")) * 60
seconds = int(input("Input seconds: "))
time = days + hours + minutes + seconds
print("The amounts of seconds", time)

If the input given is in this order: 1, 2, 3, 4



Q19. What will the following code result into?

n1, n2 = 5, 7
n3 = n1 + n2
n4 = n4 + 2
print(n1, n2, n3, n4)




Q20. Correct the following program so that it displays 33 when 30 is input.

val = input("Enter a value")
naval = val + 30
print (nval)

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Writing answers with the questions only can be very convenient but I appreciate the effort. Please keep it up

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post