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 5 4 0
- 1 5 4
- 1 4 0
- 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
- enumerate() numbers a list of names starting from 1. What line is printed?
- zip() pairs two lists of unequal length inside a loop. What total is printed?
- The inner loop's range depends on the outer loop variable. How many times does…
- When does the else block attached to a for loop run?
- A while loop halves even numbers and applies 3n + 1 to odd numbers until n…
- 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…
- Both conditions of this if-elif contain a division by x, and x is 0. What is…
- 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