博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python作业之购物商城
阅读量:6910 次
发布时间:2019-06-27

本文共 2153 字,大约阅读时间需要 7 分钟。

作业:购物商场

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 continue16 else:17 break18 19 20 def shit():21 sum = 022 TotalMoney = 100023 for i in ShoppingCartPrice:24 sum = sum + int(i)25 TotalMoney = TotalMoney - sum26 if TotalMoney > 0:27 a = input("Do you really want to buy tins ?Please enter yes or no !\n")28 if a == 'yes':29 print("Successful,wish you a happy shopping!\n")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!\n")36 37 38 39 sum = 040 TotalMoney = 100041 for i in ShoppingCartPrice:42 sum = sum + int(i)43 TotalMoney = TotalMoney - sum44 if TotalMoney > 0 :45 a = input("Do you really want to buy tins ?Please enter yes or no !\n")46 if a == 'yes':47 print("Successful,wish you a happy shopping!\n")48 exit()49 else :50 exit()51 else :52 print("Sorry,you have not enough money!Please remove somethings!\n")53 54 while True:55 print("Your shopping cart have this thing:\n")56 print(ShoppingCart)57 58 print("If you don't want to del,please enter '.'\n")59 del_thing = input("Please input the goods that you don't want to buy:\n")60 if del_thing == '.':61 break62 63 s = ShoppingCart['%s' % del_thing]64 ShoppingCart.pop('%s' % del_thing)65 66 ShoppingCartPrice.remove(s)67 68 shit()

 

  

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

 

转载于:https://www.cnblogs.com/learnC/p/5859678.html

你可能感兴趣的文章
cacti-0.8.8c 下安装realtime插件
查看>>
我的友情链接
查看>>
从0开始学大数据-Java基础开篇(1)
查看>>
github常用命令总结(一)
查看>>
Intent(意图)
查看>>
测试博客
查看>>
创建线程的方式
查看>>
微软WP7开发者体验部门主管跳槽亚马逊
查看>>
OSGi规范概要
查看>>
关系数据库的末日是否已经来临(转载)
查看>>
第二人生 我的成长
查看>>
硬编码写RadioGroup的时候要注意RadioButton的id重复问题
查看>>
周三 全身心的工作
查看>>
angularJS 1.0.6 tutorial 对应的github commit
查看>>
ldap的搭建
查看>>
利用percona-toolkit工具检查MySQL数据库主从一致性并修复
查看>>
Filter-全站GZIP压缩
查看>>
Windows自带的文件加密方法揭秘
查看>>
单页应用开发
查看>>
【Scrapy学习】 scrapyd 文件配置
查看>>