zoukankan      html  css  js  c++  java
  • Python作业之购物商城

    作业:购物商场

    1、商品展示,价格

    2、银行卡余额

    3、付账

    程序流程图如下:

    代码如下:

     1 ShopDisplay = {'clothes1':'498','jeans':'128','shoes':'289','hat':'99','clothes2':'599'}
     2 print(ShopDisplay)
     3 ShoppingCartPrice = []
     4 ShoppingCart = {}
     5 while True:
     6     thing = input("You want to buy :")
     7 
     8     price = ShopDisplay['%s' %thing]
     9     ShoppingCart.update({ '%s' %thing:'%s' %price })
    10 
    11     ShoppingCartPrice.append('%s' % price)
    12 
    13     answer = input("Do you want to continue buy something else?Please say yes or no:")
    14     if answer == 'yes':
    15         continue
    16     else:
    17         break
    18 
    19 
    20 def shit():
    21     sum = 0
    22     TotalMoney = 1000
    23     for i in ShoppingCartPrice:
    24         sum = sum + int(i)
    25         TotalMoney = TotalMoney - sum
    26         if TotalMoney > 0:
    27             a = input("Do you really want to buy tins ?Please enter yes or no !
    ")
    28             if a == 'yes':
    29                 print("Successful,wish you a happy shopping!
    ")
    30                 exit()
    31             else:
    32                 print("Thanks you for come to my shop!")
    33                 exit()
    34         else:
    35             print("Sorry,you have not enough money!Please remove somethings!
    ")
    36 
    37 
    38 
    39 sum = 0
    40 TotalMoney = 1000
    41 for i in ShoppingCartPrice:
    42     sum = sum + int(i)
    43     TotalMoney = TotalMoney - sum
    44 if TotalMoney > 0 :
    45     a = input("Do you really want to buy tins ?Please enter yes or no !
    ")
    46     if a == 'yes':
    47         print("Successful,wish you a happy shopping!
    ")
    48         exit()
    49     else :
    50         exit()
    51 else :
    52     print("Sorry,you have not enough money!Please remove somethings!
    ")
    53 
    54     while True:
    55         print("Your shopping cart have this thing:
    ")
    56         print(ShoppingCart)
    57 
    58         print("If you don't want to del,please enter '.'
    ")
    59         del_thing = input("Please input the goods that you don't want to buy:
    ")
    60         if del_thing == '.':
    61             break
    62 
    63         s = ShoppingCart['%s' % del_thing]
    64         ShoppingCart.pop('%s' % del_thing)
    65 
    66         ShoppingCartPrice.remove(s)
    67 
    68 shit()

      

    代码很简陋,作业功能基本都实现了,将就着看吧。。。。日后再来优化

  • 相关阅读:
    使用pandas的get_dummies对类目型的特征因子化
    关于RandomForestRegressor,补全null数值
    关于train_test_split和cross_val_score交叉检验
    关于seaborn
    正态分布
    单下划线或双下划线的意义
    MFC中关于运行时类信息及动态创建对象的两个宏的意义(转)
    DPDK
    根据结构体成员地址得到结构体入口地址,内核代码
    多线程频繁写全局变量导致性能降低
  • 原文地址:https://www.cnblogs.com/learnC/p/5859678.html
Copyright © 2011-2022 走看看