Python Small Code _3_ shopping Cart

Source: Internet
Author: User

Product_list = [    ('MacBook', 9000),    ('Kindle', 500),    ('Tesla', 900000),    (' Book', 100),    ('Bike', 2000),]saving= Input ("Please input your money:") Shopping_car= []ifsaving.isdigit (): Saving=int (saving) whileTrue:#Print Product Content         forI, VinchEnumerate (product_list, 1):            PrintI">>>", V)#Guide users to select ProductsChoice = input ("choose goods that's want to buy[exit:q]:")        #Verify that the input is legitimate        ifchoice.isdigit (): Choice=int (choice)ifChoice > 0 andChoice <=Len (product_list):#Select a product to be selected by choiceP_item = product_list[choice-1]                #If the money is sufficient, subtract the commodity price with saving and add the item to the shopping cart                ifP_ITEM[1] <=saving:saving-= P_item[1] Shopping_car.append (p_item)Else:                    Print("-----------------")                    Print("Sorry, your balance is not enough.")                    Print("Your Balance:"+str (saving))Print("-----------------")                    Continue                Print("-----------------")                Print("You have chose"+p_item[0])Print("Your Balance:"+str (saving))Print("-----------------")            Else:                Print("Non existent")        elifChoice = ='Q':            Print("---------------")            Print("You have chose the following goods:")            Print("Goods\t\tnumber\tprice") Num= 1#Loop through the goods in the shopping cart, the shopping cart is stored in the purchased goods             forIinchShopping_car:Print(I[0] +"\t\t"+ str (num) +"\t\t"+ STR (i[1]))            Print()            Print("Balance:", saving)Print("---------------")             Break        Else:            Print("Invalid input")

Python small Code _3_ shopping Cart

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.