用while实现登录操作(3次过后,输入yes,使counter置0,还可以玩)

                                                 用while实现登录操作(输入yes,使counter置0,还可以玩)
#_author:Administrator
#date:2019/10/24
user_name="star"
passwoed='123'

counter=0
while counter<3:
u_username=input("please input your username:")
u_password=input("please input your password:")

if u_username==user_name and u_password==passwoed:
print("welcome to %s"%u_username)
break
else:
print("your username or password is Error")
counter += 1
if counter==3:
print("Do you want to play? please choose[yse/no]")
keep_going=input("your choose:")
if keep_going=="yes":
counter=0
else:
print("Go away")
Output:

please input your username:a
please input your password:a
your username or password is Error
please input your username:a
please input your password:a
your username or password is Error
please input your username:a
please input your password:a
your username or password is Error
Do you want to play? please choose[yse/no]
your choose:yes
please input your username:
please input your password:a
your username or password is Error
please input your username:a
please input your password:a
your username or password is Error
please input your username:
please input your password:a
your username or password is Error
Do you want to play? please choose[yse/no]
your choose:a
Go away

posted @ 2019-10-24 15:37  Stary_tx  阅读(258)  评论(0编辑  收藏  举报