0

I'm doing a GCSE in computing and starting a new code for fun and I'm having trouble like a noob. I am making a code asking them what the password is and if they get it wrong it'll ask again until the requirements are met, I have looked on the internet and it gave me a countdown on all of the websites I checked. this is my code so far...

password = 1234
passinput = (input("what is your password? "))

I have tried several things such as...

while True:

and

while False:

but I don't understand how to use them properly. I have learned it in class, but it's an easy thing to forget. I want the code to keep on asking the user until they input "1234" (the password)

please help.

3 Answers3

0

The simple answer is:

while True:
    answer = input('password?')
    if answer == password:
        break

Fro more complex needs (or a better understanding of the options), see Asking the user for input until they give a valid response.

Community
  • 1
  • 1
Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
0

More simple way

password = 1234
while int(input()) != password: pass
Shreevardhan
  • 12,233
  • 3
  • 36
  • 50
0

The short way:

while True:
    if input("what's the password? ") == "1234":
        break

Or even shorter:

while input("what's the password? ") != "1234":
    pass

Or if you'd insist on a one- liner:

while input("what's the password? ") != "1234": pass
Jacob Vlijm
  • 3,099
  • 1
  • 21
  • 37