week1 homework

# 写代码
# 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
# 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
# 实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
# -----------------------------------------------------------------------------------------------------------
# count=0
# while count<3:
# name=input('username:')
# password=input('password:')
# if name=='seven'or name=='alex' and password =='123':
# print('登陆成功')
# break
# else:
# print('登陆失败')
# count+=1
# else:
# print('失败次数过多')
# -------------------------------------------------------------------------------------------------------------
# 写代码
# a. 使用while循环实现输出2-3+4-5+6...+100 的和
# b. 使用 while 循环实现输出 1,2,3,4,5, 7,8,9, 11,12
# c.使用 while 循环实现输出 1-100 内的所有奇数
# e. 使用 while 循环实现输出 1-100 内的所有偶数
# a---------------------------------------------------------------------------
# sum =0
# for i in range(2,101):
# if i%2==0:
# sum+=i
# elif i%2==1:
# sum-=i
# print(sum)
# ----------------------------------------------------------------------------
# i=1
# while i<13:
# if i==6 or i==10:
# i+=1
# continue
# print(i)
# i+=1
# ----------------------------------------------------------------------------
# i=1
# while i<101:
# if i%2==0:
# i+=1
# continue
# print(i)
# i+=1
# ---------------------------------------------------------------------------
# i = 1
# while i < 101:
# if i % 2 == 1:
# i += 1
# continue
# print(i)
# i += 1
# ---------------------------------------------------------------------------
# 现有如下两个变量,请简述 n1 和 n2 是什么关系?
#
# n1 = 123456
# n2 = n1
# print(n1 is n2,n1==n2)
# ---------------------------------------------------------------------------
# 作业:编写登陆接口
#
# 基础需求:
# 让用户输入用户名密码
# 认证成功后显示欢迎信息
# 输错三次后退出程序
# ------------------------------------------------------------------------
# count=0
# while count<3:
# name=input('username:')
# password=input('password:')
# if name=='seven'or name=='alex' and password =='123':
# print('登陆成功')
# break
# else:
# print('登陆失败')
# count+=1
# else:
# print('失败次数过多')
# ------------------------------------------------------------------------
# 基础需求:
# 让用户输入用户名密码
# 认证成功后显示欢迎信息
# 输错三次后退出程序
# 可以支持多个用户登录 (提示,通过列表存多个账户信息)
# 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)
# dic_user_info = {'hu': {'password': 'hu123', 'err times': 0}, 'egon': {'password': 'egon123', 'err times': 0}}
# count = 0
# locked_list = []
# while count < 3:
# name = input('username:')
# password = input('password:')
# with open('db') as f:
# for i in f:
# locked_list = (i.strip().split(' '))
# if not name in locked_list:
# if name in dic_user_info and password == dic_user_info[name]['password']:
# print('登陆成功')
# break
# elif name in dic_user_info and password != dic_user_info[name]['password']:
# print('密码·错误')
# dic_user_info[name]['err times'] += 1
# count += 1
# if dic_user_info[name] and dic_user_info[name]['err times'] >= 3:
# print('该用户已被锁定')
# with open('db', 'a') as f:
# f.write('%s ' % name)
# elif name not in dic_user_info:
# print('用户名错误')
# count += 1
# else:
# print('该用户已被锁定')
# else:
# print('错误次数过多')

猜你喜欢

转载自www.cnblogs.com/endlesswaltz/p/9660246.html