Bird
0
0

You want to repeatedly prompt a user for input until they type 'exit'. Which loop type is most appropriate and why?

hard📝 Application Q8 of 15
Python - While Loop
You want to repeatedly prompt a user for input until they type 'exit'. Which loop type is most appropriate and why?
AA <code>for</code> loop, because it runs a fixed number of times
BA <code>while</code> loop, because the number of inputs is unknown beforehand
CA <code>do-while</code> loop, because Python supports it natively
DNo loop is needed, just one input prompt
Step-by-Step Solution
Solution:
  1. Step 1: Understand the problem

    The user input count is unknown and depends on user typing 'exit'.
  2. Step 2: Choose loop type

    A while loop runs while a condition is true, ideal for unknown iterations.
  3. Step 3: Evaluate other options

    for loops require known iteration counts; Python lacks native do-while.
  4. Final Answer:

    A while loop, because the number of inputs is unknown beforehand -> Option B
  5. Quick Check:

    Use while loops for unknown iteration counts [OK]
Quick Trick: While loops handle unknown iteration counts well [OK]
Common Mistakes:
MISTAKES
  • Using for loops when iteration count is unknown
  • Assuming Python has do-while loops
  • Not looping at all for repeated input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes