class Shopping:
def __init__(self):
self.car = []
def shopping_car(self, itme):
self.car.append(itme)
def shopping_del(self, itme):
self.car.remove(itme)
def shopping_all(self):
if self.car:
for i in self.car:
print(i)
else:
print("快去添加你喜欢的物品吧")
def shopping_s(self):
s = 0
for i in self.car:
s += jg[i]
print(s)
jg = {"oppo": 3999, "realme": 4999, "xiaomi": 5999, "vivo": 6999, "meizu": 7999, "huawei": 8999, "apple": 9999}
shopping = Shopping()
b = 1
while(b):
b = int(input("购买物品输入1,删除物品输入2,显示购物车所有物品输入3,显示购物车总价输入4,输入0退出"))
if b == 1:
print("物品价格表", jg)
a = input("输入购买物品")
shopping.shopping_car(itme=a)
elif b == 2:
a = input("输入删除物品")
shopping.shopping_del(a)
elif b == 3:
shopping.shopping_all()
elif b == 4:
print("当前购物车一共", shopping.shopping_s(), "元")
elif b != 0:
print("请输入合法指令")
print("已退出")
© 版权声明
THE END
暂无评论内容