码迷,mamicode.com
首页 > 其他好文 > 详细

登录操作(方法二:for与else搭配)

时间:2019-10-24 15:23:52      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:代码   welcome   错误   password   user   wan   ==   time   star   

登录操作(方法二:for与else搭配)

user_name="star"
passwoed=‘123‘

count=0
for i in range(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:
count+=1
print("your username or password is Error")
else:
count==3
print("you have try more times,would you want to try again? please input yes or no,please choose")
answer=input("your choose:")
if answer==‘yes‘:
print("go away,hahahah")
Input:错误操作

please input your username:aaa
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
you have try more times,would you want to try again? please input yes or no,please choose
your choose:yes
go away,hahahah

进程已结束,退出代码0

Input:错误操作

please input your username:star
please input your password:123
welcome to star

进程已结束,退出代码0

登录操作(方法二:for与else搭配)

标签:代码   welcome   错误   password   user   wan   ==   time   star   

原文地址:https://www.cnblogs.com/startl/p/11732201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!