S
13

I finally got why my simple calculator app kept crashing...

I was trying to make a basic tip calculator in Python for my friend's cafe in Springfield, and it kept giving me an error every time someone typed in a letter instead of a number. I spent like 3 hours last night staring at the code before I realized I wasn't checking the user's input at all. Has anyone else had a program break because of bad input and found a good way to handle it for a beginner?
2 comments

Log in to join the discussion

Log In
2 Comments
miles72
miles722d agoTop Commenter
Remember thinking input validation was just extra work until my cousin's kid broke my budget tool by typing "ten" instead of 10. Now I wrap every user input in a try-except block right from the start. It feels like adding a safety net, and it saves so much headache later. For a tip calculator, you could just keep asking for the bill amount until they give you a real number. That simple loop makes it feel solid.
6
the_fiona
the_fiona2d agoMost Upvoted
Totally get what you mean about that safety net feeling. My friend built a little game for his niece and didn't validate the score input. She typed "a billion" and it crashed hard. He spent an hour fixing it when a simple check would have caught it. Your point about just looping until you get a real number is exactly right. It turns a fragile script into something that can handle real people being people. What's the weirdest input you've ever seen break something, @miles72?
10