验证登陆.笔记

# _user = "alex"
# _passwd = "abc123"
#
# counter = 0
# while counter < 3: #当 while 后面的条件成立(True),才会执行下面的代码
#
# username = input("Username:")
# password = input("Password:")
# if username == _user and password == _passwd:
# print("Welcome %s login...." % _user)
# break # 跳出,中断
# else:
# print("Invalid username or password !")
# counter += 1
# else:
# print("滚")


_user = "alex"
_passwd = "abc123"

counter = 0
while counter < 3: #当 while 后面的条件成立(True),才会执行下面的代码

username = input("Username:")
password = input("Password:")
if username == _user and password == _passwd:
print("Welcome %s login...." % _user)
break # 跳出,中断
else:
print("Invalid username or password !")
counter += 1
if counter == 3:
keep_going_choice = input("还来吗?【y/n】")
if keep_going_choice == "y":
counter = 0
else:
print("滚")

猜你喜欢

转载自www.cnblogs.com/xzdjs/p/9532217.html