From 162caa590bdfc155f7de70ef8b8e20223978fc58 Mon Sep 17 00:00:00 2001 From: pjpn35fey <1379522201@qq.com> Date: Thu, 4 Jul 2024 09:34:13 +0800 Subject: [PATCH] ADD file via upload --- python操作题答案.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 python操作题答案.txt diff --git a/python操作题答案.txt b/python操作题答案.txt new file mode 100644 index 0000000..e65c7a4 --- /dev/null +++ b/python操作题答案.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