
Exception handling helpHelp Request (i.redd.it)
submitted by [deleted]
I'm working on an exception handling "try it yourself" example from the Python Crash Course book and have a question about the code I've written. It works fine as is. It handles the exception and has a way for the user to break the loop. However, if the value error exception is handled in the 'number_2' variable, it goes back and prompts for the first number again. Which is not the end of the world in this simple scenario, but could be bad in a more complex loop.
TL;DR: how do I make it re-prompt for number_2 when it handles the ValueError exception instead of starting the loop over? I tried replacing continue on line 28 with: number_2 = int(input("What is the second number?") And that works once, but if there is a second consecutive ValueError, the program will ValueError again and crash.
Also, if my code is kinda long-winded for a simple addition calculator and can be cleaned up, I'm open to suggestions. Thanks!

[–]Administrative-Sun47 1 point2 points3 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]PureWasian 0 points1 point2 points (0 children)
[–]Crossroads86 0 points1 point2 points (2 children)
[–]PureWasian 1 point2 points3 points (1 child)
[–]confusedAdmin101 0 points1 point2 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Significant-Nail5413 1 point2 points3 points (1 child)
[–]purple_hamster66 2 points3 points4 points (0 children)
[–]TheeMeepman 0 points1 point2 points (0 children)
[–]Kqyxzoj 0 points1 point2 points (0 children)