Python Learning day2 Shopping Cart Program

Source: Internet
Author: User

Production = [    ["Apple", 7000],    ["Watch", 3000],    ["Pad", 3500],    [" Book", 100],]shopping_list=[]salary= Input ("Your Salary:")ifSalary.isdigit (): Salary=Int (Salary) whileTrue: forIndex,iteminchEnumerate (production):#Print (Production.index (item), item)            Print(index,item) Choice= Input ("What do you want to buy? ")        ifchoice.isdigit (): Choice=int (choice)ifChoice < Len (production) andChoice >=0:ifPRODUCTION[CHOICE][1] <=salary:salary-= Production[choice][1] Shopping_list.append (Production[choice])Print("you have already purchased%s and left \033[41;1m%s\033[0m."%(production[choice][0],salary))Else:                    Print("you don't have enough money.")            Else:                Print("the item you want to buy does not exist")        elifChoice = ="Q":            Print("--------Shopping list----------")             forPinchshopping_list:Print(P)Print("your money is still left.", Salary) exit ()Else:            Print("Please re-enter the product code")Else:    Print("Please re-enter")

Note: Notice the use of the For loop, such as the first for loop, after print the next choice should be at the same level as for to print out the complete list of items, otherwise it will be as follows

Your salary:9000'apple' 7000ni xianng mai shen me?0 ..... ' Watch ' ...

In the process of writing to pay attention to clear thinking, step by step, you can on the paper flow chart, more practice.

Kill must be a knife in the throat, Wu bei for learning, when from the heart of the marrow of the delicate force, natural tokujitsu brilliant.

Python Learning day2 Shopping Cart Program

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.