Python Shopping Cart

Source: Internet
Author: User

Functional Requirements:

Require users to enter total assets, for example: 2000
Display the list of items, let the user select the item according to the serial number, add the shopping cart
Purchase, if the total amount of goods is greater than the total assets, indicating that the account balance is insufficient, otherwise, the purchase succeeds.
Add: Can recharge, a product to remove the shopping cart
goods = [
{"Name": "Computer", "Price": 1999},
{"Name": "Mouse", "Price": 10},
{"Name": "Yacht", "Price": 20},
{"Name": "Beauty", "Price": 998},
]

shoping=[]goods= [    {"name":"Computer"," Price": 1999},    {"name":"Mouse"," Price": 10},    {"name":"Yacht"," Price": 20},    {"name":"Beauty"," Price": 998},] whiletrue:salary=input ('Your Salary:')    ifsalary.isdigit (): Int (Salary) Break    Else:        Continue whileTrue:#Print (goods)     forIndex, IinchEnumerate (goods):Print(Index,'.', i["name"],i[" Price"]) Choice= Input ('Please select a product number to purchase:') Salary=Int (Salary)ifchoice.isdigit (): Choice=int (choice)ifChoice >=0 andChoice <len (Goods): P=Goods[choice]#Print (p)            ifSalary >=p[' Price']: Salary-= p[" Price"] Shoping.append (p)Print("Added \033[32;1m[%s]\033[0m into your shopping cart,and you are balance"%(p['name'], salary))Else:                Print("you don't have enough money.") Chongzhi=input ('If you need to recharge y/n:')                ifChongzhi = ="Y" orChongzhi = ='y': Salary_chongzhi=input ("Please enter the amount of the recharge")                    ifsalary_chongzhi.isdigit (): Salary_chongzhi=Int (Salary_chongzhi) Salary=salary_chongzhi+SalaryElse:                    Continue    elifChoice = ='Delete':         forIndex, IinchEnumerate (shoping):Print(Index,'.', i['name'], i[' Price']) Delete= Input ('Please enter the item number you want to delete:')        ifdelete.isdigit (): Delete=Int (delete)#if delete >=0 and delete < Len (shoping):salary+=shoping[delete][' Price'] Shoping.pop (delete)elifChoice = =' Shop':        Print(shoping)elifchoice=="quit":        Print("List of items you purchased:", Shoping) exit ()
View Code

Python Shopping Cart

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.