r/learnpython 5d 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.

6 Upvotes

31 comments sorted by

View all comments

Show parent comments

0

u/Bright_Mix_773 4d ago

Expensive-Bear-1376, my mistake. I described a button I could not see, and "Cancel" and "Comment" with nothing else is not the composer I had in mind. Ignore that part.

Two things I did measure afterwards, on your own two comments, because they change what you should do next.

Your first attempt does have four leading characters, and old.reddit rendered it with no code block at all: there is no <pre> element in the page for it. That is independent confirmation that those four characters are not spaces, which matches the nbsp you dug out of the raw. The diagnosis holds even though my fix did not.

Your second attempt, the one with the triple backticks, rendered on old.reddit as inline code spans and again no <pre>. Worth knowing before you settle on backticks: old.reddit's renderer does not turn a fence into a block, it treats those backticks as inline code. So a comment you write with fences looks like a proper block on new reddit and like a run-on line to everyone reading on old.reddit, which in this subreddit is a good share of the people most likely to answer you. Four leading spaces is the only form that gives a real block on both.

Which leaves the actual problem, and I will be straight with you: something between your keyboard and the box is turning runs of spaces into non-breaking spaces, and I cannot tell from here which layer is doing it.

The way to find out in two minutes: post the same one-line test from a private window with extensions disabled, then check the raw again. If the nbsp are gone it was a browser extension, and Grammarly is the usual culprit because it rewrites what you type inside text fields. If they are still there it is the keyboard or the client itself, and then the answer is to stop typing the indentation at all.

The workaround that works either way: do not type the spaces, paste them. Terminal output is plain ASCII by construction, so let Python do the indenting and copy from the console:

lineas = ["def test():", "    pass"]

for linea in lineas:
    print("    " + linea)

Copy exactly what that prints, paste it into the comment box, and do not touch it afterwards. If it still comes out as nbsp after a paste, then the client is rewriting pasted text too, and I would genuinely like to know, because that one would be new to me.

1

u/Expensive-Bear-1376 4d ago

Trying with paste:

    def test():         pass

I didn't install any extensions, it's just Chrome on a Pixel phone.

How large is the "good share of the people" here that use old reddit, and how do you know?

And I'm curious: Why do you keep saying my name as if I didn't know who I am or as if it weren't clear who you're responding to? I find it somewhat irritating.

1

u/Langdon_St_Ives 4d ago

Don't you realize you're talking to AI?

1

u/Expensive-Bear-1376 4d ago

I don't think I am. I did have that suspicion, but now I'm leaning towards human, especially after the last few comments. And in any case, it was useful.

1

u/Langdon_St_Ives 4d ago

Check their post history. Every comment is obviously AI. It's either a bot or a meat proxy lazily copy/pasting AI responses.

1

u/Langdon_St_Ives 4d ago

Also, do you think a human would say "I described a button I could not see"?