A simple shopping cart written in Python

Source: Internet
Author: User
#coding Utf-8
#1, design a shopping cart program, prompting the user to enter wages, pay input after opening the product list, prompting the user to select the product to buy
#2, select a product, if the balance is sufficient, the purchase succeeds, and the product list is printed, otherwise the purchase fails, showing the balance

Salary=int (Input ("Please enter your salary limit:"))
goodslist=[[' Sony color TV ', 3888],[' Apple Computer ', 8999],[' wok ', 199],["Iphone6", 3888],["teacup", 77]
Changgoodlist=[]
I=1
Print ("The item you entered is as follows:")
For good in Goodslist:
Print ("%d---%s----%d"% (I,good[0],good[1])
I+=1

Flag=true

While flag:
changgoodnumber = Int (Input ("Select the item you want to buy:"))
If Changgoodnumber<=len (goodslist):
if int (salary)-goodslist[changgoodnumber-1][1]>=0:
Print ("Your purchase was%s"% (goodslist[changgoodnumber-1][0))
Changgoodlist.append (Goodslist[changgoodnumber-1][0])
Salary=salary-int (Goodslist[changgoodnumber-1][1])
Print ("Your salary balance is%d Yuan"%salary)
Else
Print ("Insufficient balance, cannot buy, program exits")
Flag=false
Else
Print ("No this item, please re-select")

A simple shopping cart written in Python

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.