App 1: Your First App, a Quiz Game / Build the quiz
Lesson 7 of 10
Handle bad input
Players type weird things. If someone types 'banana' instead of a number, your app shouldn't crash or count it. Check with .isdigit() and ask again.
Key points
- Loop until the input is valid
- .isdigit() checks for a whole number
- Friendly messages, not crashes
while True:
pick = input("Your choice (1-3): ").strip()
if pick.isdigit() and 1 <= int(pick) <= 3:
break
print("Please type 1, 2 or 3.")Your turn
Make your quiz keep asking until the player types a valid choice.
Quiz · +10 XP
What does "12".isdigit() return?
Log in to save progress and earn XP.