WorksheetsIdiomatic Python
Total questions: 13
Worksheet time: 15mins
What will happen if I run the following code:
x=1+2j
y=1+2*j
Error because of x
Error because of y
print(x) would give 1+2j
print(y) would give 1+2j
What will happen if I run the following code:
1)float(3.5)
2)float(3)
3)float("Hello")
Ans 1) 3.5
Ans 2) 3
Ans 2) 3.0
Ans 3) Error
Ans 3) 5.0
9/2 and 9%2=
4, 1
4.5, 0
4, 0
4.5,1
9/2 and 9./2 will give the same result
True
False
(9./2)%0.5=
Hint: Don't write an integer!
(a)
n = 17
print(n%2==0),print(n%2==1)
write the result as F,F or T,T similarly
(a)
9.0+2=
(a)
x = 2.0*(1+2j); print(x.real)
(a)
3*4**5 == (3*4)**5
True
False
x,y = 1,2; x,y = x-y, x+y; print(x,y)
x,y = 1,2; x,y = y, x; print(x,y)
x,y = 1,2; x -= 1; y+=1; print(x,y)
Write your answer in the following format :
1,1;1,1;1,1
(a)
from math import sqrt; sqrt(2 + 2j)
from cmath import sqrt; sqrt(2 + 2j)
from cmath import sqrt; from math import sqrt; sqrt(2 +2j)
Error,Error, Error
Error, No Error, Error
No Error,Error, No Error
No Error, No Error, No Error
list(range(7))
Write your answer as [1,2,3...]
(a)
list(range(2,7,2))
same format as before
(a)
