1 Star 0 Fork 0

Danyyao/Homework

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
026课Homework.py 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
Danyyao 提交于 2024-12-07 22:01 +08:00 . Homework
""""
自定义一个用户账户密码登录程序
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() # 打印新行
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/danyyao/homework.git
git@gitee.com:danyyao/homework.git
danyyao
homework
Homework
master

搜索帮助