What should a Leeds quiz sign-up do if you leave your name blank?
You're signing up for a school quiz in Leeds. You press Enter without typing your name, then try a team code that's only two characters long. How should the form help you fix each entry?
Start with input. It reads what you type. If you press Enter without typing anything, input returns an empty string. Give that empty string to len. There are no characters to count, so len returns zero.
An empty name fails. Jo passes the presence check because it contains characters. This simple rule even counts spaces. For the team code, A B fails and A B C passes. The minimum length is three. These checks tell you whether entries meet the rules, not whether the name really belongs to you.
The name field contains just A, and the team code contains A B. The name only needs something in it, and the code needs at least three characters. Pick which entries the form should accept.
Read the name once. While its length is zero, ask again and store the new name. After the name passes, read the team code. While its length is less than three, ask again and store the new code. Each loop tests the latest entry.
The empty name has length zero, so the loop reads again. Mia has three characters, so the name loop ends. A B has two characters, fewer than three, so the code loop reads again. L D S has exactly three characters, so the code loop ends and keeps it.
The minimum length is three. The user is ready to type X, U K, Y R K and then Leeds, in that order, if the program keeps asking. Pick the code the program keeps when the loop ends.
Start with A B and reply A B C. The first loop discards the reply, so A B stays stored. That’s a logic error. The second loop stores A B C and exits. The third loop is missing a colon. That’s a syntax error, so Python cannot run the code.
If the exam asks you to write code to validate both inputs, read the name and retry while it’s empty. Then read the team code and retry while it’s shorter than three characters. Store each fresh reply. A name that passes satisfies the rule, even if it isn't the user's real name.