一个登录小程序

username

passwd

  • 让用户输入账号和密码,输入用户和密码输入正确的话
  • 提示你  xxx,欢迎登录,今天的日期是xxx,程序结束
  • 错误的话,提示账号/密码输入错误
  • 最多输入3次,如果输入3次都没有登录成功,提示失败次数过多。
  • 需要判断输入是否为空,输入空也算输入错误一次

#  登录程序
#  最多输入错误3次                循环
#     账号密码,                       input
#     要校验输入为空的情况,
#     输入错误3次的话,要提示错误次数过多


import datetime
uname= 'niuhanyang'
pwd='123456'
count = 0
today = datetime.date.today()
while count<3:
    username = input('请输入账号:').strip()
    passwd = input('请输入密码:').strip()
    if username==uname and passwd==pwd:
        welcome = '欢迎【%s】登录,今天的日期是【%s】'%(username,today)
        print(welcome)
        break
    elif username=='' or passwd=='':
        print('账号/密码不能为空')
    else:
        print('账号/密码错误')
    count += 1
else:
    print('错误次数过多')


today = datetime.date.today()
for i in range(3):
    username = input('请输入账号:').strip()
    passwd = input('请输入密码:').strip()
    if username==uname and passwd==pwd:
        welcome = '欢迎【%s】登录,今天的日期是【%s】'%(username,today)
        print(welcome)
        break
    elif username=='' or passwd=='':
        print('账号/密码不能为空')
    else:
        print('账号/密码错误')
else:
    print('错误次数过多')

 

原文地址:https://www.cnblogs.com/jiadan/p/8666911.html