1 #-*-coding:utf-8-*-2 #@Time: 2018-05-31 14:563 #@Author: Superman4 #@Email: [Email protected]5 #@File: Shopping cart Little Practice6 #@Software: Pycharm7 8 9Goods_list = [Ten['Apple', 30], One['Car', 80000], A['Tesla', 999999], -['Computer', 20000] - ] theShopping_car=[] -Money = input ('Please enter your purchase amount:') - ifmoney.isdigit (): -money=Int (money) + whileTrue: - forI,oinchEnumerate (goods_list): + Print(I,o) Agoods_id = input ('Please enter the purchased product serial number [exit Q]:') at ifgoods_id.isdigit (): -Goods_id=Int (goods_id) - ifGoods_id>=0 andgoods_id<Len (goods_list): -Goods_price=goods_list[goods_id] -Money=money-goods_price[1] - ifMoney>0: in Print(Goods_price) - shopping_car.append (Goods_price) to Else: + Print('Insufficient Balance') - Break the Else: * Print('Product number does not exist') $ elifgoods_id = ='Q':Panax Notoginseng Print('-----------------------Buy the following items-------------------------------') - forIinchShopping_car: the Print(i) + Print('remaining%s dollars'%Money ) A Break the Else: + Print('Please enter a valid character!')
Python Simple shopping Cart small code