23
TIL my simple calculator program broke because I used a single equals sign
I was making a basic tip calculator in Python last night and it kept giving me an error... turns out I wrote 'if total = 10:' instead of 'if total == 10:'. That one extra equals sign makes all the difference between assigning a value and checking if it's equal. Has anyone else had a tiny syntax mistake that took you forever to spot?
3 comments
Log in to join the discussion
Log In3 Comments
butler.brian25d ago
That's the worst kind of bug to track down.
7
simonw4119h ago
Actually Python 3.8 and up throws a syntax error for that exact case... so it would break.
4
seth_wells4925d ago
You said it "broke" your program, but did it really? A single equals in an IF statement would just assign the value 10 to total, which is always truthy in Python. It might not even throw an error, just give you weird logic. That's annoying, but not exactly broken.
2