1 # bug分开添加同一种商品到购物车的时候 会以两种商品打印
2 # 未对用户输入的字符串进行判断
3 goods_name = [
4 {"Name": "MI 8", "Price": 3699},
5 {"Name": "MI 6", "Price": 2699},
6 {"Name": "MI mini", "Price": 169},
7 {"Name": "MI watch", "Price": 179},
8 ]
9 print("Welcome to Rainm's shopping center!!\nWhat do you want to do:")
10 choice = input("1. Enter the shop\n2. I am just looking")
11 shopping_car = []
12 flag = True
13 total = 0
14 if choice == '2':
15 print("See you next time")
16 else:
17 print("Nice to meet you, here are good: ")
18 while flag:
19 for i, k in enumerate(goods_name): #枚举??
20 print("No.{} {} {}".format(i + 1, k["Name"], k["Price"]))
21 goods_choice = int(input("Which goods you want to add it to your shopping car(Press -1 to exit): "))
22 if goods_choice == -1:
23 print("What do you want to do:")
24 next_choice = input("1. check shopping car\n2. I want to see the next store")
25 if next_choice == '1':
26 print("Here are your shopping car: ")
27 for k in shopping_car:
28 print("Name: {} Price: {} Count:{}".format(k["Name"], k["Price"], k["Count"]))
29 total += int(k["Price"] * goods_num)
30 print("Total:{}$".format(total))
31 else:
32 print("See you next time.")
33 break
34 flag = False
35 print("What do you want to do: ")
36 next_choice1 = input("1. Balance my shopping car.\n2. Continue to shopping.\n3. Exit the store.")
37 if next_choice1 == '1':
38 shopping_car.clear()
39 print("Balance successfully!!It totally costs {}$\nHaving a nice day!".format(total))
40 elif next_choice1 == '2':
41 flag = True
42
43 else:
44 goods_num = int(input("And how much do you want to buy: "))
45 shopping_car.append({"Name": goods_name[goods_choice - 1]["Name"], "Price": goods_name[goods_choice - 1]["Price"], "Count": goods_num})