Preliminary discussion on Python-Shopping Cart Program

Source: Internet
Author: User

Requirements:

1, after the user enters, has the welcome language and prompts the user to enter the principal

2, the user entered the correct content after the shopping menu displayed to the user

3, when the user's principal is not sufficient to purchase the goods when there is a hint that the balance is insufficient and inform the difference

4, after successful shopping prompted the purchase of content and after the purchase of the balance, can repeat the purchase

5, the end of the time to inform users to buy the contents and balance of the goods

Print("------------******-----------") Menu= [["MacBook", 9000],["iphone", 4500],["Bick", 800],["Pythonbook", 80],["Cup", 50]]shopping_car=[]a=True whileA = =true:balance= Input ("Please enter the amount you have [Q Exit]:")    ifbalance.isdigit (): Balance=int (balance) whileTrue: forIinchRange (0,len (menu)):Print(Str (i + 1) +","+ menu[i][0],menu[i][1]) Choice= (Input ("Please enter the required product serial number [Q Exit]"))            ifchoice.isdigit (): Choice=int (choice)if0 < Choice <=Len (menu): price= Int (menu[choice-1][1])                    ifPrice <=balance:balance-=Price shopping_car.append (Menu[choice-1])                        Print("has been added"+ str (menu[choice-1][0]) +"to your shopping cart, balance"+ str (balance) +". Please continue shopping. ")                    Else:                        Print("Insufficient Balance"+ STR (balance-price) +"Please re-select. ")            elifChoice = ="Q":                Print("you have purchased the following items")                 forIinchRange (0, Len (shopping_car)):Print(Str (i + 1) +","+ shopping_car[i][0], shopping_car[i][1])                Print("The current balance is:"+str (balance)) a=False Break            Else:                Print("Please enter the correct number")    elifBalance = ="Q":        Print("you have not purchased a product. ")         Break    Else:        Print("Please enter the correct amount")
shopping cart. PY

Beginner python, the primary way to write notes. Laughed at

Preliminary discussion on Python-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.