题目如下:
用户登录需求:
1.输入用户名和密码;
2.判断用户名和密码是否正确(name='root',passwd='westos')
3.登录仅有三次机会,超过3次会报错
代码如下:
"""
# _*_coding:utf-8_*_
Name:user.py
Date:1/14/19
Author:westos-sql
Connect:2910903196@qq.com
Desc:...
"""
for i in range(3):
name = input('name:')
passwd = input('passwd:')
if name == 'root' and passwd == 'westos':
print('success!')
break
else:
print('failed')
print('You have %d chance' %(2 - i))
else:
print('Please login later!')
执行结果:
1、执行两次第三次成功:
2、第一次成功:
3、三次失败,提示用户稍后再登陆: