我的代码中的while循环没有循环。
我尝试确保while循环会循环,但不执行任何循环。
#Name_Input
login = 1
while login == 1:
print("Enter the username and password \n")
username = input("Username: ")
password = input("Password: ")
if password and username != "cameron" and "123":
print("\nWrong username or password... \nTry Again...")
login = 1
我期望在错误输入登录详细信息时循环返回到登录。
答案 0 :(得分:2)
login = 1
while login == 1:
print("Enter the username and password \n")
username = str(input("Username: "))
password = str(input("Password: "))
if username == "cameron" and password == "123":
login=2
else:
print("\nWrong username or password... \nTry Again...")
答案 1 :(得分:1)
请尝试以下语法:
login = 1
while login == 1:
print("Enter the username and password \n")
username = input("Username: ")
password = input("Password: ")
if password != "123" or username != "cameron":
print("\nWrong username or password... \nTry Again...")
login = 1
else:
login = -1