wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Idiomatic Python

Total questions: 13

Worksheet time: 15mins

Name
Class
Date
1.

What will happen if I run the following code:

x=1+2j

y=1+2*j

a)

Error because of x

b)

Error because of y

c)

print(x) would give 1+2j

d)

print(y) would give 1+2j

2.

What will happen if I run the following code:

1)float(3.5)

2)float(3)

3)float("Hello")

a)

Ans 1) 3.5

b)

Ans 2) 3

c)

Ans 2) 3.0

d)

Ans 3) Error

e)

Ans 3) 5.0

3.

9/2 and 9%2=

a)

4, 1

b)

4.5, 0

c)

4, 0

d)

4.5,1

4.

9/2 and 9./2 will give the same result

a)

True

b)

False

5.

(9./2)%0.5=

Hint: Don't write an integer!

(a)  

6.

n = 17

print(n%2==0),print(n%2==1)

write the result as F,F or T,T similarly

(a)  

7.

9.0+2=

(a)  

8.

x = 2.0*(1+2j); print(x.real)

(a)  

9.

3*4**5 == (3*4)**5

a)

True

b)

False

10.

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)  

11.

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)

a)

Error,Error, Error

b)

Error, No Error, Error

c)

No Error,Error, No Error

d)

No Error, No Error, No Error

12.

list(range(7))


Write your answer as [1,2,3...]

(a)  

13.

list(range(2,7,2))

same format as before

(a)