Content · Programming · Python

Python Count User Answers Until a Stop Word

An open-ended input loop repeats until a specified sentinel text is entered. Normalizing whitespace and case can make the stop word easier to recognize. Learn with a clear example and common mistakes to avoid.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

This guide explains Count User Answers Until a Stop Word through a focused example and practical reasoning. No prior knowledge of this specific operation is required.

Understanding the Concept


An open-ended input loop repeats until a specified sentinel text is entered. Normalizing whitespace and case can make the stop word easier to recognize.

When You Would Use This


Collect responses until the user types done.

Step-by-Step Example


response_count = 0
while True:
    response = input("Answer (done to stop): ").strip()
    if response.lower() == "done":
        break
    if response:
        response_count += 1
print("Answers received:", response_count)

How the Example Works


The loop counts nonempty answers and exits on any capitalization of done. Empty answers are ignored.

Try It Yourself


Change the program so it also counts blank responses separately.

Common Beginner Mistakes


  • Counting the stop word as an answer.
  • Forgetting to strip whitespace around the stop word.
  • Confusing an empty answer with end-of-file in automated input.

Key Takeaways


  • An open-ended input loop repeats until a specified sentinel text is entered.
  • The loop counts nonempty answers and exits on any capitalization of done.
  • Avoid this mistake: Counting the stop word as an answer.
Share this resourceSend this page to someone who may find it useful.