代码拉取完成,页面将自动刷新
""""
自定义一个用户账户密码登录程序
1. 使用循环,在输入错误时,让用户持续输入
2. 输入正确时,显示登录成功,并退出循环
3. 如果连续输错达到五次,进行关闭
"""
correct_account = input("请先设置您的账户名:")
correct_psd = int(input("请先设置您的正确的6位随机数字密码:"))#这一步可嵌入上次作业,自动生成多位数随机高强度密码。
print("用户注册成功!")
yy_judge = True
i = 1
while yy_judge:
input_account = input("请输入您的账户名:")
input_psd = int(input(f"请输入您的密码(您只有{6-i}次机会):"))
if input_psd == correct_psd and input_account == correct_account and i <= 5:
print("登录成功!")
yy_judge = False
elif input_psd != correct_psd and i <= 4:
print(f"您输入的密码错误,再想想!您还剩{5-i}次机会了!")
i += 1
elif input_account != correct_account and i <= 4:
print(f"您输入的账户名错误,再想想!您还剩{5-i}次机会了!")
i += 1
else:
print("您的账户已被锁定,请联系堯堯解锁!")
yy_judge = False
print()
# 优化建议:加入设置位数限制,报错机制,UI等等。此次就不展示了。
# 加入了简易动画(胡大)
# import sys
# import time
#
#
# def progress_bar(total, prefix='进度', suffix='完成', length=50, fill='█'):
#
# for i in range(total + 1):
# percent = 100 * (i / float(total))
# filled_length = int(length * i // total)
# bar = fill * filled_length + '-' * (length - filled_length)
# sys.stdout.write(f'\r{prefix} |{bar}| {percent:.1f}% {suffix}')
# sys.stdout.flush()
# time.sleep(0.05) # 模拟工作过程
# print() # 打印新行
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。