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")
  1. ZeroDivisionError
  2. big
  3. safe
  4. 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

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