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?
2 comments

Log in to join the discussion

Log In
2 Comments
sethh12
sethh1215d 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
keving9315d ago
Wrapping it in try/except... I tried that once and still messed it up somehow.
1