The Secret Life of Python: The Safety Net ('try' and 'except')
The Secret Life of Python: The Safety Net ('try' and 'except') # python # coding # programming # softwaredevelopment Understanding try , except , and Input Validation. Timothy was beaming. "I learned my lesson from last time," he told Margaret. "I updated my guessing game. Now I use int() to cast the user's input into a number immediately. No more silent bugs!" "That is excellent progress," Margaret said, moving her chair closer. "But what happens if the user doesn't follow instructions?" "What do you mean?" Timothy asked. "It says 'Guess a number'. Why wouldn't they type a number?" "Users are creative," Margaret smiled. "Watch." She leaned over and ran his program. Prompt: Guess the number (1-10): Margaret typed: five Output: Traceback (most recent call last): File "game.py", line 3, in <module> guess = int(input("Guess the number (1-1...