-2
if userInput != userPassword:
   print("I'm sorry, that is wrong please try again. Try to remember capitals!")
elif userInput == userPassword:
    print("That is correct you may now find out your mobile phone costs!")
    mobile_phone()

When that runs and I enter the wrong password it just repeats the first print statement (I'm sorry, that is wrong please try again. Try to remember capitals!) how can I make it just run it again ONCE and if it is wrong then maybe another time until it is answered with the right password. Debut Post

  • 1
    I presume this is for educational purposes, rather than real production code? Production code *must not* store plain-text passwords. Instead they must store salted hashes, and use a computationally expensive hash function like Argon2, scrypt, or bcrypt. See https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016 – Martin Bonner supports Monica Apr 03 '18 at 15:04

1 Answers1

3

Put it in a while loop ?

while (userInput != userPass) :
    print ("wrong password")
    // reask userPass

And in case you want to limit the number of trys, let say 3 for the example, just add a counter:

while (userInput != userPass && counter < 3) :
    counter++
    print ("wrong password")
    // reask userPass
N.K
  • 1,601
  • 2
  • 19
  • 31
  • Note tha the OP asks to prompt and reread *just once* – Martin Bonner supports Monica Apr 03 '18 at 14:56
  • 1
    @MartinBonner not sure: "how can I make it just run it again ONCE and if it is wrong ***then maybe another time until it is answered with the right password.***", i may be wrong, but sounds like he just want to run it until the good pass is entered, but thanks i'll add some precision to my answer just in case :). – N.K Apr 03 '18 at 14:58
  • @MartinBonner Based on the title and body of this question, `while` loop is appropriate here – Programmer Apr 03 '18 at 20:24