Write a shopping cart program in Python

Source: Internet
Author: User

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)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.