# user_dict = {"用户名": "密码"}
# 1. 支持新用户注册(添加),新用户名和密码注册到字典中
# 2. 支持老用户登陆(查询),用户名和密码正确提示登陆成功
# 3. 主程序通过循环询问,进行何种操作,根据用户的选择,执行注册或是登陆操作
user_dict = {"zs": "123"} # 用于保存用户信息
def login(): # 登陆
username = input("用户名: ")
pwd = input("密码: ")
# 登陆成功: 当用户名存在以及密码正确
if username in user_dict.keys() and user_dict.get(username) == pwd:
print("登陆成功")
else:
print("登陆失败")
def register(): # 注册
username = input("用户名: ")
if username in user_dict.keys(): # 用户名存在
print("用户名存在, 不能注册")
else: # 将用户名和密码添加到字典中
pwd = input("密码: ")
user_dict[username] = pwd # 添加
def show_menu():
while True:
choice = input("1:登录 2:注册 3:退出, 请选择: ")
if choice not in ["1", "2", "3"]:
print("无效的输入")
elif choice == "3":
print("byebye~")
break
elif choice == "1":
login()
else: # choice == "2"
register()
if __name__ == '__main__':
show_menu()
python----24---模拟用户登录信息系统
最新推荐文章于 2023-10-29 13:19:45 发布