user_list = []
user_port = []
ls_login = False
ls_quit = True
ls_q =True
while ls_quit:
n = input("1.注册 2.登录 3.退出\n")
if n == '1':
user_name = input("请输入用户名称:")
user_password = input("请输入登录密码:")
user = [user_name, user_password]
user_list.append(user)
print("注册成功!\n")
elif n == '2':
user_name = input("请输入用户名:")
user_password = input("请输入登录密码:")
found_user = False
for user in user_list:
if user[0] == user_name and user[1] == user_password:
ls_login = True
ls_quit = False
found_user = True
print("登录成功!欢迎登录。")
break
if not found_user:
print("用户名或密码错误,请重新输入")
elif n == '3':
ls_quit = False
if ls_login:
print("您已成功退出。")
else:
print("再见!")
else:
print("无效的选项,请重新输入。")
if ls_login:
while ls_q :
print("请选择你的操作:1:增加商品 2: 删除商品 3: 修改商品 4: 查看商品\n")
w = input()
if w == '1':
port_name = input("请输入商品名字")
port_number = input("请输入商品编号")
port = [port_name, port_number]
user_port.append(port)
print("添加成功!\n")
elif w == '2':
print("请输入商品名称及编号:\n")
port_name = input("请输入商品名称:\n")
port_number =input("请输入商品编号:\n")
found_port = False
for port in user_port:
if port[0] == port_name and port[1] == port_number:
user_port.remove(port)
found_port = True
print("删除成功")
break
if not found_port:
print("未查询到相关商品")
elif w == '3':
port_name = input("请输入需要修改的商品名称:\n")
port_number = input("请输入需要修改的商品的编号:\n")
for port in user_port:
if port[0] == port_name and port[1] == port_number:
user_port.remove(port)
new_port_name = input("请输入修改后的商品名称:\n")
new_port_number = input("请输入修改后的商品编号:\n")
new_port = [new_port_name, new_port_number]
user_port.append(new_port)
print("修改成功!")
else:
print("未查询到相关商品!请重新输入:")
elif w == '4':
print("商品名单:\n")
for port in user_port:
print(f"商品名称:{port[0]},商品编号:{port[1]}")
port_name = input("请输入需要查询的商品名称:\n")
port_number = input("请输入需要查询的商品编号:\n")
for port in user_port:
if port[0] == port_name and port[1] ==port_number:
print(f"商品名称:{port_name},商品名称:{port_number}")
else:
print("无效输入,请重新输入")
使用python建立一个简单的增删改查用户和商品文件
最新推荐文章于 2024-08-16 18:55:06 发布