choice4 = input("最后一层,按b返回>>:")
if choice4 == "b":
pass
elif choice4 == "q":
exit_flag = True
if choice3 == "b":
break
elif choice3 == "q":
exit_flag = True
if choice2 == "b":
break
elif choice2 == "q":
exit_flag = True
十一、作业
购物车
用户入口:
1、商品信息存在文件里
2、已购商品,余额记录
商家入口:
2、可以添加商品,修改商品价格
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 用户或者是商家
# 用户-登陆信息-卡里剩多少钱-打开商品列表-选择商品-打印已购商品,余额记录
# 商家-登陆信息-添加商品/修改商品价格-存入文件
user_info = {"zhangsan":[333333,30000],"lisi":[444444,40000],"wangwu":[555555,50000]}
shopper_info = {"hhh":666666}
user = input("user:")
password = input("password:")
shopping_list = []
product_list = open("product_list.txt").readlines()
if user in user_info and int(user_info[user][0]) == int(password):
salary = int(user_info[user][1])
print("Welcome %s to our shopping center!Your salary is %s" % (user, salary))
while True:
for k, v in enumerate(product_list):
print(k, v)
choice = input("Which product do you want to select?")
shopping_list.append(product_list[int(choice)])
shop_price = int(product_list[int(choice)].split(":")[1])
salary -= shop_price
print("Your shopping_list is %s and your salary is %s" % (shopping_list, salary))
choice2 = input("Do you want to continue to shopping?")
if choice2 == "n":
print("Welcome to you next time!Your shopping_list is %s and your salary is %s" % (shopping_list, salary))
break
elif choice2 == "y":
pass
elif user in shopper_info and int(shopper_info[user]) == int(password):
while True:
print("1 add product\n""2 modify price")
choice3 = input("What do you want to do?")
if choice3 == "1":
product = input("Which product do you want to add?")
&nbs