Recover From Errors (Exercise)
00:00
Yet another way of controlling the flow of your Python program is error handling. So, you can use try
and except
to catch and handle errors and influence the way that your program executes using these structures.
00:13 So, this is what you’re supposed to do in this task that is called Recover from Errors. It says, “Write a program that repeatedly asks the user to input an integer.
00:22
If the user enters something other than an integer, then the program should catch the ValueError
and display the message "Try again."
” instead of quitting the program, right?
00:30 “Once the user enters an integer, the program should display the number back to the user and then end,” and the program should never crash. You’re supposed to catch a common error that could happen when the user inputs something that you want to convert to an integer, but it’s not convertible to an integer, then the program would otherwise crash.
00:48 But your task here is to catch and handle that exception. Give it a try, and in the next lesson, you’ll see a possible solution.
Become a Member to join the conversation.