O
21

I tried to make a simple number guessing game in Python and it broke in a weird way

I was following a tutorial to make a basic game where the computer picks a number and you guess it. I wrote the code, but when I ran it, it just kept asking for a guess forever, even after I got it right. I stared at my screen for an hour, totally stuck. The problem was I used a single equals sign in an 'if' statement instead of a double equals sign. My line said 'if guess = random_number:' which is wrong. It should have been 'if guess == random_number:'. That one little symbol made the whole program act crazy. I felt so silly when I finally saw it. It taught me to check my symbols twice. Has anyone else had a simple typo break their code for way too long?
3 comments

Log in to join the discussion

Log In
3 Comments
garcia.laura
Oh man, I feel this one deep in my soul. The single equals sign is like the gremlin of Python, hiding in plain sight just to mess with you. I remember a time I spent like three hours debugging a loop that would never stop, and it turned out I had a 'while True:' that I forgot to break out of because of a similar typo. @zara572 is totally right about that afternoon of despair over a missing comma, honestly code editors should have a "make fun of you" feature for these moments. It's like the computer is gaslighting you into thinking you don't know how to program, when really it's just a forgotten double equals sign pulling a prank. At least now you'll never make that mistake again, or you'll make it again but catch it faster, which is basically the same thing.
4
thea857
thea8571mo ago
Check your equals signs, that mistake has wasted hours of my life too.
1
zara572
zara5721mo ago
Honestly @thea857, that feeling when you finally spot the tiny typo is the worst. Tbh I once spent a whole afternoon on a missing comma in some code. It really makes you want to scream.
7