Python for Shopping cart optimization

Source: Internet
Author: User

Functional Requirements:
Require users to enter their own 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.
goods = [
{"Name": "Computer", "Price": 1999},
{"Name": "Mouse", "Price": 10},
{"Name": "Yacht", "Price": 20},
{"Name": "Beauty", "Price": 998},
]‘‘‘
Goods = [    {"name":"Computer"," Price": 1999},    {"name":"Mouse"," Price": 10},    {"name":"Yacht"," Price": 20},    {"name":"Beauty"," Price": 998},] whileTrue:name=input ("Enter user name:") Mima=input ("Please enter user password:")    ifName = ="Qi" andMima = ="123":        Print("Landing Success")         Break    Else:        Print("incorrect user name or password") Money= Int (Input ("Total Assets")) LST=[] while1:    Print('----------Product List------------')     forI,minchEnumerate (goods):Print(i,m) Select=input ("Please select the item you want to buy:")    ifselect.isdigit ():if0<=int (SELECT) <len (Goods): s=goods[int (SELECT)] a=s.get (" Price")           Print(a)ifA >=Money :Print("Insufficient account balance")           Else: w= S.get (" Price") Moneys=money-WPrint("The balance is left .", Moneys) lst.append (s)Print(LST)Print("Purchase Success")        Else:            Print('Select wrong, please re-select')    elifselect = ='Q':        Print('--------------Select a list of items-------------')         forI,vinchEnumerate (LST):Print(i,v) Break

Python for Shopping cart optimization

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.