0
information = input("Enter your information:\n")
password = ""
password = input("Enter your password!:\n")
password_confirmation = input("Enter your password to confirm!\n")
if password == password_confirmation:
    print("Password saved\n")
    print("Do you want to lock the system? (Yes[1]/No[2])")
    choice = input("Please enter 1 or 2")
    if choice == "1":
        print("System locked!\n")
        userpass = input("Enter password to access to info\n")
        if userpass == password:
            print(information)
        else:
            print("Wrong password\n")
    elif choice == "2":
        print("Warning system is unlocked\n")
    else:
        print("====use 1 or 2=== (Yes[1]/No[2])\n")
        print("Do you want to lock the system? (Yes[1]/No[2])\n")
        choice = input()
        if choice == 1:
            print("System locked!\n")
        elif choice == 2:
            print("Warning system is still unlocked\n")
        else:
            print("wtf")
elif password_confirmation != password:
    print("Passwords does not match!\n")

I tried to make it by making variables like confirm = 0 and using conditions to ask again but it does not ask after 2nd time. Im a beginner at python so I couldnt find any solution.

1 Answers1

0

You could just use a while loop that keeps running as long as passwords don't match:

information = input("Enter your information:\n")
password = ""
password = input("Enter your password!:\n")
password_confirmation = input("Enter your password to confirm!\n")

while password_confirmation != password:
    password_confirmation = input("Passwords didn't match. Please try again: ")

After the loop quits you can go directly to the rest of the code:

print("Password saved\n")
print("Do you want to lock the system? (Yes[1]/No[2])")
choice = input("Please enter 1 or 2")
if choice == "1":
    print("System locked!\n")
    userpass = input("Enter password to access to info\n")
    if userpass == password:
        print(information)
    else:
        print("Wrong password\n")
elif choice == "2":
    print("Warning system is unlocked\n")
else:
    print("====use 1 or 2=== (Yes[1]/No[2])\n")
    print("Do you want to lock the system? (Yes[1]/No[2])\n")
    choice = input()
    if choice == 1:
        print("System locked!\n")
    elif choice == 2:
        print("Warning system is still unlocked\n")
    else:
        print("wtf")
NotAName
  • 3,821
  • 2
  • 29
  • 44