What should a GAA club survey do if you type “great” instead of a rating from 1 to 5?
Your GAA club asks you to rate a match from one to five. You type ‘great’, then zero, then five. Which entry should the survey accept, and how can it keep asking without getting stuck?
One pass is one trip through the loop body. An instruction in the body can run again on the next pass. Think of a running total: each pass uses the same addition instruction, but it adds the next number.
Python's input function gives you text. Check for exactly one digit from zero to nine. If that check fails, ask again. If it passes, convert the digit to an integer. Accept the number if it's from one to five, including both ends. Otherwise, ask again.
The survey expects one digit, and the user types the word ‘five’. It names a number in the right range, so what should the program do with the entry? Pick the best answer.
The function loops, reading fresh text each pass. Check for exactly one digit from zero to nine before converting. If the number is in range, return it and leave the function. If either check fails, print the error and repeat. The last line calls the function and stores the result.
First, the word ‘great’ fails the format check. Skip conversion and the range check, then ask again. The next entry, zero, converts to an integer but is below one, so ask again. Five converts, passes the range check and is returned. The function stops asking.
Now the user types ‘ten’, then nine, then three. Follow each entry through the format check and, if it gets that far, the range check. Pick the option that gives the result of each pass.
On the left, the program reads zero once and never replaces it. Printing an error doesn't change the entry, so the loop keeps testing the same zero. On the right, the loop reads input on every pass, so after a rejection it tests a fresh entry.
If you're asked to outline the algorithm in pseudocode, start with the function and its loop. Read the entry, check its format, then convert it and check the range. Return the rating if both checks pass. Otherwise, display the error and let the loop read a new entry.