Conditions & Loops · Question 19 · Hard
Both conditions of this if-elif contain a division by x, and x is 0. What is printed?
x = 0
y = 5
if x and y / x > 1:
print("big")
elif not x or y / x:
print("safe")
else:
print("small")
- ZeroDivisionError
- big
- safe
- small
Answer and explanation
Answer: C. safe
Explanation: x is 0, which is false, so and stops without evaluating y / x and the if branch is skipped. In the elif, not x is True, so or stops without evaluating y / x. No division ever happens and safe is printed.
Previous: The loop variable is changed inside the body of a for loop. What does this… · Next: continue comes after the increment inside a while loop. What list is built?
Practise conditions & loops
Try a fresh set of conditions & loops questions with an explanation after every answer, free and without signing up: Conditions & Loops practice. Or sit a full placement mock test.
More conditions & loops questions
- break appears inside the inner of two nested loops. Which pairs are collected?
- A while loop with an else clause tests whether 91 has a small divisor. What…
- The loop variable is changed inside the body of a for loop. What does this…
- continue comes after the increment inside a while loop. What list is built?
More python practice
Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge