password = "12345"
# user_name = input("please input your username:")
# user_password = input("please input your user_password:")
_flag = "y"
while True:
flag = input("please input your flag:")
if flag == _flag:
user_name = input("please input your username:")
user_password = input("please input your user_password:")
if user_name == user and user_password == password:
print("welcome to logining")
else:
print("invalid user_name or user_password")
else:
break
?
# 限制登录的次数为3次
for i in range(3):
user_name = input("please input your username:")
user_password = input("please input your user_password:")
if user_name == user and user_password == password:
print("welcome to logining")
break
else:
print("invalid user_name or user_password")
# 如果登录了3次还是错的,程序自动跳出并给出提示
?
passed_authentication = False # 这个变量在我们的程序中作为一种flag
for i in range(3):
user_name = input("please input your username:")
user_password = input("please input your user_password:")
if user_name == user and user_password == password:
print("welcome to logining")
passed_authentication = True # 真
break
else:
print("invalid user_name or user_password")
if not passed_authentication:
print("Already pass,break!!!")
for i in range(3):
user_name = input("please input your username:")
user_password = input("please input your user_password:")
if user_name == user and user_password == password:
print("welcome to logining")
break
else:
print("invalid user_name or user_password")
else: # 只要上面的for循环正常执行,中间没有被打断,就会执行这个else语句
print("输入的次数超过了规定")