Conditions & Loops · Question 13 · Medium

A helper function prints its argument each time it is called inside and / or conditions. What is printed?

def check(x):
    print(x, end=" ")
    return x > 2

if check(1) and check(5):
    pass
if check(4) or check(0):
    pass
  1. 1 5 4 0
  2. 1 5 4
  3. 1 4 0
  4. 1 4
Answer and explanation

Answer: D. 1 4

Explanation: and stops at the first false operand: check(1) is False, so check(5) is never called. or stops at the first true operand: check(4) is True, so check(0) is never called. Only 1 and 4 are printed.

Previous: The inner loop's range depends on the outer loop variable. How many times does… · Next: When does the else block attached to a for loop run?

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