python系统学习:第一周之循环

  利用零散时间已经将第一周的内容学习完毕,接下来就是完成视频的课后作业。以下是作业内容。

 

# Author : Sunny
'''
# Work_num1:编写登陆接口
· 输入用户名和密码
· 认证成功后显示欢迎用户登录
· 输错三次后锁定
'''
# 设置默认用户及密码
_username = "sunny"
_passwd = "123456"
# 进入循环
for i in range(3):
username = input("username:")
passwd = input("passwd:")
# 判断
if _username == username and _passwd == passwd:
print("Welcome to back!{0}.".format(username))
break
else:
print("Invalid Your username or passwd!")
else:
print("Fuck Off!")
# 写法二
_username = "sunny"
_passwd = "123456"
_count = 0
# 进入循环
while _count < 3:
username = input("username:")
passwd = input("passwd:")
if _username == username and _passwd == passwd:
print("Welcome back!{0}.".format(username))
break
else:
print("Invalid Your username or passwd!")
_count += 1
if _count == 3:
continue_confirm = input("Continue?Y/N")
if continue_confirm == "Y":
_count = 0
else:
print("Fuck Off!!!")
/* 喜欢的同学加我博客一起讨论*/
 
posted @ 2018-10-24 16:16  牛屎虫  阅读(158)  评论(0编辑  收藏  举报