2
Update: I tried to make a simple calculator in Python and it kept crashing
I followed a tutorial to make a calculator that adds two numbers. I used the input() function and typed '5' and 'three'. The program crashed with a ValueError. I learned that input() always gives you text, even if you type a number, so you need int() to change it. Has anyone found a better way to handle this without the program stopping?
3 comments
Log in to join the discussion
Log In3 Comments
sethh122mo ago
Yeah, wrapping the int() conversion in a try/except block is the move. That way it can catch the error and ask for the number again instead of just crashing.
2
riley581mo ago
Totally agree with try/except, but you gotta make sure the except block actually prints a clear message so the user knows what to type instead.
0