Python MCQs on variable and operators: SET 2

11. What is the output of the following code : print 31//2

A. 15

B. 15.5

C. 15.0

D. Error

Check Answer

Answer: A
due to floor division ”//”, the decimal part is removed

 

 

12. Which is the correct operator to calculate power of a raise to b?

a) a^b

b) a**b

c) a^^b

d) None of these

Check Answer

Answer: b
** operator is used for power in Python.

 

 

13. Which of the following operator is used for floor division?

a) %

b) /

c) //

d) None of these

Check Answer
Answer: c
// is the correct operator for floor division.

 

 

14. Arrange this in order of Precedence.

i) Division

ii) Addition

iii) Subtraction

iv) Parentheses

v) Exponential

vi) Multiplication

a) i,ii,iii,iv,v,vi

b) ii,i,iii,iv,v,vi

c) iv,iii,v,vi,i,ii

d) iv,v,vi,i,ii,iii

Check Answer

Answer: d
Remember PEMDAS(Parentheses,Exponential, Multiplication, Division, Addition, Subtraction ) for Order of Precedence

 

 

15. What will be the output of this expression, 37 % 5 is?

a) 1

b) 2

c) 0

d) 7

Check Answer
Answer: b
Modulus operator gives the remainder.so 2 will be the output.

 

 

16. What will be the output of statment 3*1**3 ?

a) 1

b) 9

c) 27

d) 3

Check Answer
Answer: d
here exponential has higher precedence than multiplication so 1**3 will be sloved first.

 

 

17. Operators with the same precedence are evaluated from?

a) Right to Left

b) Left to Right

c) Can’t say

d) None of these

Check Answer
Answer: b
Operators with the same precedence are evaluated from left to right.

 

 

18. How many Global and local variables are there in this Python code?

a=10

def fn():

a=7

b=a+5

a=20

fn()

A. 1 local, 1 global variables

B. 1 local, 2 global variables

C. 2 local, 2 global variables

D. 2 local, 1 global variables

Check Answer
Answer: c

 

 

19. What is the output of statment 2**2**2**2 ?

A. 16

B. 256

C. 32768

D. 65536

Check Answer
Answer: d
This statment is equivalent to 2^16. so answer is 65536.

 

 

20. Which one of the following has the highest precedence in the expression?

a) Exponential

b) Addition

c) Multiplication

d) Subtraction

Check Answer
Answer: a

Pages  1  2

 

Leave a Comment