Evaluating Expression in Python Important Question Answer
— Page 2 —
Que 8. Evaluate the following expression and identify the correct answer.
print ( round (100.0 / 4 + (3 + 2.55) , 1 ) )
(a) 30.0
(b) 30.55
(c) 30.6
(d) 31.0
Answer: (c) 30.6
Reason: Operator execution sequence as per precedence are (+), /, +, round()
=> print( round (100.0 / 4 + (3 + 2.55) , 1 ) )
=> print( round (100.0 / 4 + 5.55 , 1 ) )
=> print( round (25.0 + 5.55 , 1 ) )
=> print( round (30.55 , 1 ) )
=> print( 30.6 )
=> 30.6
Que 9. Choose one option from the following that will be the correct output after executing the given python expression.
print(True or not True and False)
(a) True
(b) False
(c) or
(d) not
Answer: (a) True
Reason: Operator execution sequence as per precedence are not, and, or
=> print(True or not True and False)
=> print(True or False and False)
=> print(True or False )
=> print(True )
=> True
Que 10. What will be the output of the following python expression?
24/6%3 , 24//4//2 , 2**3**2
(a) (1.0, 12, 64)
(b) (1.0, 3, 512)
(c) (1, 12, 512)
(d) ERROR
Answer: (b) (1.0, 3, 512)
Reason: Except **, all operators work from left to right, while ** work from right to left.
=> 24/6%3 , 24//4//2 , 2**3**2
=> 4.0%3 , 6//2 , 2**9
=> 1.0, 3, 512
Que 11. Choose one option from the following that will be the correct output after executing the given python expression.
not 50 or 44 and 60 and ‘Python’
(a) True
(b) False
(c) 60
(d) Python
Answer: (d) ‘Python’
Reason: Operator execution sequence as per precedence are not, and, or
In Python, 0, ”, 0.0 having truth value is False, while other values like 5, -5, 6.0, ‘hello’ are having truth value is True.
and => and operator returns the second value if the first value is having truth value of True, otherwise, return the first value.
or => or operator returns the first value if the first value is having truth value of True, otherwise, return the second value.
=> not 50 or 44 and 60 and ‘Python’
=> False or 44 and 60 and ‘Python’
=> False or 60 and ‘Python’
=> False or ‘Python’
=> ‘Python’
Que 12. What will the following expression be evaluated in Python?
print(25 // 4 + 3 ** 1 ** 2 * 2)
(a) 24
(b) 18
(c) 6
(d) 12
Answer: (d) 12
Reason: Operator execution sequence as per precedence are **, //, *, +
=> print(25 // 4 + 3 ** 1 ** 2 * 2)
=> print(25 // 4 + 3 ** 1 * 2)
=> print(25 // 4 + 3 * 2)
=> print( 6 + 3 * 2)
=> print( 6 + 6)
=> print( 12)
=> 12
Que 13. What will the following expression be evaluated in Python?
not True and False or not True
(a) True
(b) False
(c) NONE
(d) NULL
Answer: (b) False
Reason: Operator execution sequence as per precedence are not, and, or
=> not True and False or not True
=> False and False or not True
=> False and False or False
=> False or False
=> False
Que 14. What will the following expression be evaluated in Python?
not False and False or True
(a) True
(b) False
(c) NONE
(d) NULL
Answer: (a) True
Reason: Operator execution sequence as per precedence are not, and, or
=> not False and False or True
=> True and False or True
=> False or True
=> True
Que 15. What will the following expression be evaluated in Python?
print(16 – ( 3 + 2 ) * 5 + 2 ** 3 * 4)
(a) 54
(b) 46
(c) 23
(d) 32
Answer: (c) 23
Reason: Operator execution sequence as per precedence are (+), **, *, -, +
=> print(16 – ( 3 + 2 ) * 5 + 2 ** 3 * 4)
=> print(16 – 5 * 5 + 2 ** 3 * 4)
=> print(16 – 5 * 5 + 8 * 4)
=> print(16 – 25 + 32)
=> print( -9 + 32)
=> print(23)
=> 23