根据提示,在右侧编辑器补充代码,模拟用户登录系统。 系统有多个用户,用户信息保存在列表users中,现在进行用户登录判断。提示用户输入用户名。如果输入的用户名不在列表中,提示用户名不存在,重新登录,总共三次登录机会。如果输入的用户名在列表中,提示用户输入密码。如果密码不正确,重新输入,总共三次机会。若三次错误,提示次数用尽,请稍后再试!
时间: 2023-06-13 10:02:08 浏览: 96
```python
users = [{"username": "Alice", "password": "123456"}, {"username": "Bob", "password": "abcdef"}, {"username": "Charlie", "password": "password123"}]
for i in range(3):
username = input("请输入用户名:")
password_input_count = 0
user_exist = False
for user in users:
if user["username"] == username:
user_exist = True
while password_input_count < 3:
password = input("请输入密码:")
if user["password"] == password:
print("登录成功!")
exit()
else:
password_input_count += 1
print(f"密码错误!还剩{3-password_input_count}次机会")
print("密码输入错误次数已用尽,请稍后再试!")
exit()
if not user_exist:
print("用户名不存在!请重新输入!")
print("登录失败,次数已用尽,请稍后再试!")
```