首页 > 代码库 > Python作业之购物商城
Python作业之购物商城
作业:购物商场
1、商品展示,价格
2、银行卡余额
3、付账
程序流程图如下:
代码如下:
ShopDisplay = {‘clothes1‘:‘498‘,‘jeans‘:‘128‘,‘shoes‘:‘289‘,‘hat‘:‘99‘,‘clothes2‘:‘599‘}print(ShopDisplay)ShoppingCartPrice = [] #购物车商品价格ShoppingCart = {} #购物车while True: thing = input("You want to buy :") price = ShopDisplay[‘%s‘ %thing] ShoppingCart.update({ ‘%s‘ %thing:‘%s‘ %price }) ShoppingCartPrice.append(‘%s‘ % price) answer = input("Do you want to continue buy something else?Please say yes or no:\n") if answer == ‘yes‘: continue else: breakdef shit(): #判断余额是否大于所要买的商品 sum = 0 TotalMoney = 1000 for i in ShoppingCartPrice: sum = sum + int(i) TotalMoney = TotalMoney - sum if TotalMoney > 0: a = input("Do you really want to buy tins ?Please enter yes or no !\n") if a == ‘yes‘: print("Successful,wish you a happy shopping!\n") else: print("Thanks you for come to my ") exit() else: print("Sorry,you have not enough money!Please remove somethings!\n")sum = 0TotalMoney = 1000for i in ShoppingCartPrice: sum = sum + int(i) TotalMoney = TotalMoney - sumif TotalMoney > 0 : a = input("Do you really want to buy tins ?Please enter yes or no !\n") if a == ‘yes‘: print("Successful,wish you a happy shopping!\n") exit() else : exit()else : print("Sorry,you have not enough money!Please remove somethings!\n") while True: print("Your shopping cart have this thing:\n") print(ShoppingCart) print("If you don‘t want to del,please enter ‘.‘\n") del_thing = input("Please input the goods that you don‘t want to buy:\n") if del_thing == ‘.‘: break s = ShoppingCart[‘%s‘ % del_thing] ShoppingCart.pop(‘%s‘ % del_thing) ShoppingCartPrice.remove(s) #删除不买的东西shit()
代码很简陋,作业功能基本都实现了,将就着看吧。。。。日后再来优化
Python作业之购物商城
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。