循环 while 和 for

#1、写一个登陆的程序,最多登陆失败3次
#2、输入账号 密码,如果登录成功,程序结束,提示 欢迎 xx 登录,今天的日期是 xx
#3、登录失败,重新登陆
#3、要判断输入是否为空,什么也不输入,输入空格都算算空

import datetime
now_time = datetime.datetime.now().strftime('%Y-%m-%d')

a = "yajuan"
b = "123456"
count = 0
while 循环
while count < 3:
user_name = input('请输入用户名字:')
password = input('请数字:')

count = count + 1
if user_name == a and password == b:
print('''欢迎%s登录,今天的日期是%s'''%(user_name,now_time))
break
elif user_name == '' or user_name.isspace():
print('请输入有效的名字')
continue

else:
print("登录失败,重新登陆")

else:
print("已使用3次机会,登录已关闭")




for 循环
for count in range(5):
user_name = input('请输入用户名字:')
password = input('请数字:')
if user_name == a and password == b:
print('''欢迎%s登录,今天的日期是%s'''%(user_name,now_time))
break
elif user_name == '' or user_name.isspace():
print('请输入有效的名字')
continue

else:
print("登录失败,重新登陆")

else:
print("已使用5次机会,登录已关闭")


posted @ 2019-08-02 22:43  遇见最好的你_juan  阅读(138)  评论(0编辑  收藏  举报