python学习第一天


# 1、写一个登陆的小程序
# username = tanailing
# passwd = 123456
# 1、输入账号密码,输入正确就登陆成功,
# 提示欢迎xxxx登陆,今天的日期是多少
# 2、最多输入错误3次
# 账号/密码错误,请重新登陆
# 3、如果失败测试超过3次,提示,失败次数过多
# 4、要校验输入是否为空,如果输入为空,你要提示账号./密码不能为空
# 什么都不输入和输入一个空格多个空格都算空。
# 输入为空也算操作错误一次

import datetime

date=datetime.date.today()
count = 0
while count < 3:
count += 1


username = input('请输入用户名:'+'\n')
password = input('请输入密码:'+'\n')

hopeName = 'tanailing'
hopePasswd = '123456'

if not username.strip() or not password.strip():
print('账号或者密码不能为空'+'\t'+'还剩下', 3-count , '次机会')
continue

elif username == hopeName and password == hopePasswd:
print('欢迎{}登陆,今天的日期是{}'.format(username,date))
break
else:
print('账号或者密码错误,请重新登陆'+'\t'+'还剩下', 3-count , '次机会')

else:
print('超过3次,登录失败')

 

学习心得:
1、常用内置库
datetime
2、字符串输入的判空。if not password.strip() #strip()函数是指将字符串前后都去空。
3、continue 表示结束本次循环,继续执行下一次循环,continue下面的代码当次循环中不执行。
4、while else:此else是表示,当while全部执行完后,正常的执行一次。但,遇到break 则不会执行。

 


posted @ 2018-08-18 22:26  花er壹樣的女人  阅读(162)  评论(0编辑  收藏  举报