Python - 如何摆脱 while 循环



我正在尝试制作登录菜单。我创建了一个可更改的用户/通行证系统。但是我想退出循环,要求他们再次输入用户名/密码?

以下是源代码:

print ("Welcome, please login.")
username = input("Please set a username")
password = input("Please set a password")
print ("please can you login")
username_input = input("What is your username?")
password_input = input ("What is your password?")
if username_input == username and password_input == password:
    while 1==1:
        print ("1. Change username")
        print ("2. Change password")
        print ("3. Go back to login menu")
        print ("4. Exit")
        option = int(input("Please select an option, 1/2/3/4?"))
        if option == 1:
            username = input("Enter a new username")
            print ("You username is now",username)
        elif option == 2:
            password = input("Enter a new password")
            print ("Your password is now",password)
        elif option == 3:
            #Help
        elif option == 4:
            quit()

你想出圈,因此

break

是你的答案。你能更清楚一点你到底想做什么吗?

如果你仍然需要这个答案:

Value = 2
While value == 2
print ("1. Change username")
print ("2. Change password")
print ("3. Go back to login menu")
print ("4. Exit")
option = int(input("Please select an option, 1/2/3/4?"))
if option == 1:
    username = input("Enter a new username")
    print ("You username is now",username)
    Value = 1
elif option == 2:
    password = input("Enter a new password")
    print ("Your password is now",password)
    Value = 1
elif option == 3:
    Pass
elif option == 4:
    quit()

最新更新