• Mini program


    1.Shopping cart

     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!!
    What do you want to do:")
    10 choice = input("1. Enter the shop
    2. 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
    2. 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.
    2. Continue to shopping.
    3. Exit the store.")
    37             if next_choice1 == '1':
    38                 shopping_car.clear()
    39                 print("Balance successfully!!It totally costs {}$
    Having 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})
  • 相关阅读:
    eyou通用标签的调取
    eyou头部相关标签的调用
    自增标签循环+1的方法
    文章内容页相关的标签
    当前栏目有多少文章
    指定栏目最顶级栏目名称
    当前单页正文
    Python-pandas常用函数
    监控在线平台
    网页爬虫---音乐
  • 原文地址:https://www.cnblogs.com/Rainm/p/9618096.html
Copyright © 2020-2023  润新知