From f4e41712906eb6648d6f195e9964c2b3a91b9aa4 Mon Sep 17 00:00:00 2001 From: p4pye3fz9 <2720296995@qq.com> Date: Wed, 3 Jul 2024 23:18:48 +0800 Subject: [PATCH] ADD file via upload --- python操作题答案(1).txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 python操作题答案(1).txt diff --git a/python操作题答案(1).txt b/python操作题答案(1).txt new file mode 100644 index 0000000..e65c7a4 --- /dev/null +++ b/python操作题答案(1).txt @@ -0,0 +1,30 @@ +import time +# 假设的用户数据 +USER_DATA = { + 'username': 'admin', + 'password': '1234' +} +# 尝试次数限制 +MAX_ATTEMPTS = 3 + +def login(): + attempts = 0 + while attempts < MAX_ATTEMPTS: + # 从命令行获取用户名和密码 + username = input("请输入用户名:") + password = input("请输入密码:") + + # 验证用户名和密码 + if USER_DATA['username'] == username and USER_DATA['password'] == password: + print("登录成功") + return True + else: + print("登录失败,用户名或密码错误") + attempts += 1 + print(f"您还有 {MAX_ATTEMPTS - attempts} 次尝试机会。") + + print("登录失败次数过多,账户被锁定。") + return False + +if __name__ == "__main__": + login() \ No newline at end of file