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()