zoukankan      html  css  js  c++  java
  • 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})
  • 相关阅读:
    java_windows下修改eclipse的默认编码
    54. Spiral Matrix (Graph)
    74. Search a 2D Matrix (Graph; Divide-and-Conquer)
    48. Rotate Image (Array)
    119. Pascal's Triangle II (Graph; WFS)
    118. Pascal's Triangle (Array)
    127. Word Ladder (Tree, Queue; WFS)
    117. Populating Next Right Pointers in Each Node II (Tree; WFS)
    116. Populating Next Right Pointers in Each Node (Tree; WFS)
    107. Binary Tree Level Order Traversal II(Tree, WFS)
  • 原文地址:https://www.cnblogs.com/Rainm/p/9618096.html
Copyright © 2011-2022 走看看