11
Tried to code a calculator in Python and it kept telling me 2+2 = 22
I'm like 3 weeks into learning Python, just doing basic stuff. So I figured I'd write a simple calculator that adds two numbers. Simple, right? I wrote the whole thing, ran it, and typed in 2 and 2. It printed out 22 instead of 4. I stared at my screen for like 10 minutes thinking I broke math itself. Turns out I forgot to convert my input from a string to an integer. The program was just gluing the text together instead of adding numbers. My buddy who's been coding for years saw me screenshot my code and send it to him in a panic. He just laughed and said "classic rookie move." Has anyone else had a moment where you spent way too long debugging something that was just one tiny thing? I feel like I need to write a checklist for myself or something.
3 comments
Log in to join the discussion
Log In3 Comments
kevin33113d ago
Classic rookie move" nailed it. Print statements after every line saved my sanity.
4
jason_stone5913d agoMost Upvoted
Print statements after every line" is basically the only way I got through my first real coding project. I remember putting them in the most ridiculous places, like right after a variable assignment just to make sure it actually stored the right value. It's embarrassing looking back but that's what debugging looks like when you're starting out. The funny thing is even now when something weird happens I'll still throw in a few print statements before trying anything fancy. There's something about seeing the exact value at each step that just makes everything click.
3
the_jake13d ago
Read something online where a guy spent three hours debugging his code and the whole problem was he used a capital letter in one place but lowercase in another. That's the kind of stuff that makes you just sit and stare at your screen. Your string vs integer thing is a classic. Everyone I know who's tried coding has that exact same story with forgetting to cast their input. You're not alone, coding is just a constant string of tiny stupid mistakes like that.
1