_user = "Alex"
_pwd = "123"
flag = False
for i in range(3):
user_input = input("Enter your login user:")
pwd_input = input("Enter your login password:")
if user_input == _user and pwd_input == _pwd:
print("Hi , %s , Wellcome login you CSDN." % user_input)
flag = True
break
else:
print("Your user or password not right!")
if not flag:
print("小婊砸,你已经试了 %d" % (i+1),"次了!别玩了,程序已经停下来了")
_user = "Alex"
_pwd = "123"
counter = 0
while counter < 3:
username = input("Enter your login user:")
pwssword = input("Enter your login password:")
if username == _user and pwssword == _pwd:
print("Hi , %s , Wellcome login you CSDN." % username)
break # break for 后,就不会执行最下面的else语句
else:
print("Your user or password not right!")
counter += 1
else:#只要上面的for循环正常执行完毕,中间没有被打断,就会执行else语句
print("小婊砸,你已经试了 %d" % (counter),"次了!别玩了,程序已经停下来了")
重点
_user = "Alex"
_pwd = "123"
for i in range(3):
username = input("Enter your login user:")
pwssword = input("Enter your login password:")
if username == _user and pwssword == _pwd:
print("Hi , %s , Wellcome login you 博客园." % username)
break # break for 后,就不会执行最下面的else语句
else:
print("Your user or password not right!")
else:#只要上面的for循环正常执行完毕,中间没有被打断,就会执行else语句
print("大兄弟,你已经试了 %d" % (i+1),"次了!别玩了,程序已经停下来了")