登录小程序
写一个登录的程序:
1、最多登陆失败3次
2、登录成功,提示欢迎xx登录,今天的日期是xxx,程序结束
3、要检验输入是否为空,账号和密码不能为空
4、账号不区分大小写
1 import datetime #导入时间模块 2 today = datetime.datetime.today() #定义时间变量 3 user = 'Test' #正确的用户名 4 password = 'Aa123456' #正确的密码 5 count = 0 6 while count<3: 7 count+=1 8 uname = input('请输入用户名:') 9 upass = input('请输入密码:') 10 msg1 = '欢迎 %s登录,今天的日期是 %s' %(uname,today) 11 if not uname.strip() or not upass.strip() : #检查用户名和密码是否为空 12 print('用户名或密码不能为空') 13 continue 14 elif uname.lower() != user.lower() or upass.lower() !=password.lower() : #账号不区分大小写 15 print('用户名或密码错误') 16 continue 17 else: 18 print(msg1) 19 break 20 else: 21 print('登录失败次数超过3次,不允许登录')
posted on 2019-09-06 09:31 cathyg1234 阅读(289) 评论(0) 收藏 举报
浙公网安备 33010602011771号