Conditions & Loops · Question 8 · Medium

A for loop that searches for an even number has an else clause. What does this print?

for n in [3, 5, 7]:
    if n % 2 == 0:
        print("even")
        break
else:
    print("no even")
  1. even
  2. even no even
  3. no even
  4. SyntaxError
Answer and explanation

Answer: C. no even

Explanation: The else of a loop runs only when the loop finishes without hitting break. None of 3, 5, 7 is even, so break never runs and the else block prints no even.

Previous: A loop over the letters of a word stops at the letter p. What is printed? · Next: continue is used inside a loop over range(1, 8). Which numbers are printed?

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