Two strings that look similar to a person can differ in capitalization or surrounding spaces. A program needs a clear rule for whether those differences matter.
Worked example
For a simple yes-or-no prompt, stripping surrounding whitespace and converting the answer to lowercase lets Yes, YES, and yes follow the same branch. Apply those operations before comparing the answer with the accepted words. Keep the original answer if you need to display exactly what the player typed.
What to check
Try an answer with spaces, a different capitalization, and an unrecognized word. Normalizing text should follow the purpose of the task. A password or a code may require exact matching, while a friendly menu can accept several equivalent spellings. Avoid changing information automatically when that change would alter its intended meaning. A short list of accepted inputs makes the interaction easier to explain and test.
Continue with the book
Explore the full treatment, worked examples, and exercises in Code Quest with Python.
Companion article for Code Quest with Python, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
