Write a shopping cart program in Python
#! /Usr/bin/env python #-*-coding: UTF-8-*-# _ auth by kk def goods_list (): shangpin = {"iphone": "6000 ", "MacAir": "15000", "tea": "50", "book ": "30"} print "-" * 12 + u "product list" + "-" * 12 for key in shangpin: print "goods: % s --> price: % s "% (key, shangpin [key]) print"-"* 12 + u" commodity list "+"-"* 12 return shangpin def jiesuan (money, shangpin_list ): sheng_money = money while True: qt = raw_input (u "do you need to shop? Y/n \ n ") if qt =" y ": gou_goods = raw_input (u", enter the name of the product you want to purchase. For the purchased product, see the product list: \ n ") if gou_goods in shangpin_list: sheng_money = int (sheng_money)-int (shangpin_list [gou_goods]) if sheng_money> = 0: print" you purchased % s product, total consumption % s. You have % s RMB left! "% (Gou_goods, shangpin_list [gou_goods], sheng_money) else: print" you have insufficient money. Please recharge your account. Welcome to visit us next time! "Break else: print" No such item! "Else: print" Welcome next time! "Break if _ name __= = '_ main _': shangpin_list = goods_list () try: money = raw_input (u" Please recharge your account before purchasing the product, enter the Recharge Amount: \ n ") print" Your Recharge Amount is % s. The recharge is successful! "% (Money) failed t IOError, e: print" input error. Please check! "Jiesuan (money, shangpin_list)