Python Writing Shopping Cart program

Source: Internet
Author: User

I am not talkative, no nonsense, directly on the code:

#!/usr/bin/env python# -*- coding: utf-8 -*-#_auth  by kkdef goods_list ():     shangpin={"iphone": "6000", "MacAir": "15000", "Tea": "", "book": "The"}     print  "-" *12 +u "Product List"  + "-" *12    for key in  shangpin:        print  "Goods: %s --> price:  %s " %  (Key,shangpin[key])     print "-"*12 +u" Product List " +"-"*12     return shangpindef 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 "Please enter the name of the product you want to buy, please refer to 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 have purchased the%s product, total consumption  %s,  you have  %s dollars left! " %  (Gou_goods,shangpin_list[gou_goods],sheng_money)                  else:                     print  "Your money is not enough, please recharge, welcome to the next visit!" "                     break            else:                 print  "No this item! "        else:             print  "Welcome to the next visit!" "            breakif __name__==  ' __main_ _ ':     shangpin_list=goods_list ()     try:         money=raw_input (U "please recharge after the purchase of goods, please enter the amount of recharge: \ n")          print  "Your recharge amount is  %s, the top up is successful!" "%  (Money)     except IOError,e:         print  "Input error, please check!"     jiesuan (Money,shangpin_list)


This article is from the "Microsoft" blog, so be sure to keep this source http://1238306.blog.51cto.com/1228306/1709677

Python Writing Shopping Cart program

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.