T
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 In
3 Comments
sethh12
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
keving93
keving932mo ago
Wrapping it in try/except... I tried that once and still messed it up somehow.
1
riley58
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