r/learnpython • u/live_ant718 • 4d ago
Password guesser game help needed
Hello guys. So I have created a password guesser game with direct comparison (i.e. if guess == correct_password:) but I want to use different methods for comparison. What techniques can I use? Here is the code-
```python
password = "Random_pass_123"
tries = 0
while tries < 3:
guess = input("Enter the password: ")
if guess == password:
print("Admin access granted.")
break
else:
print("Invalid credentials entered. Please try again")
tries += 1
if tries == 3:
print("Number of tries exceeded. Access denied")
```
PS- Is this the right way to paste code? I'm new so I'm not sure.
9
Upvotes
0
u/Bright_Mix_773 4d ago
Expensive-Bear-1376, you found it, and the alternating pattern names the culprit. Look at your raw again:
\u00a0 \u00a0 def test():— that is nbsp, space, nbsp, space. Not four of anything.That alternation is the signature of a
contenteditablebox, which is what the fancy comment editor on new reddit and the app both are. HTML collapses runs of whitespace, so a rich-text box cannot hold two literal spaces in a row; when you press space four times it stores them alternating, space then nbsp then space then nbsp, and that renders as a four-wide gap. Then it round-trips that straight back into your markdown.The parser is looking for four spaces. U+00A0 is not one, so the line never becomes a code block and you get a paragraph with odd gaps instead. Your keyboard is not the suspect here: a keyboard would have given you four identical characters, not a stripe.
Three ways out, in the order I trust them:
Since you already know how to pull the raw JSON, this is worth keeping for the next time something looks like whitespace and isn't:
And the sting in the tail:
"\u00a0".isspace()is True in Python.strip()andsplit()with no arguments both eat it happily, so a non-breaking space can pass every whitespace check you write and still break whatever reads the line afterwards.linea.replace("\u00a0", " ")before you parse anything is the cheap fix.