Conditions & Loops · Question 7 · Easy

A loop over the letters of a word stops at the letter p. What is printed?

for ch in "campus":
    if ch == "p":
        break
    print(ch, end="")
  1. cam
  2. camp
  3. camus
  4. us
Answer and explanation

Answer: A. cam

Explanation: The loop prints c, a and m. When ch is p, break ends the loop immediately, before the print line, so p and the letters after it are never printed.

Previous: range() is given a negative step. What list does this print? · Next: A for loop that searches for an even number has an else clause. What does this…

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