Python Road Day2 Shopping Cart applet 1

Source: Internet
Author: User

1 #Author:ersa2 " "3 Program: Shopping Cart Program4 5 Requirements:6 7 After you start the program, let the user enter the payroll, and then print the list of items8 allow users to purchase items based on their product number9 after the user selects the product, checks whether the balance is enough, enough on the direct debit, enough to remindTen you can exit at any time to print the purchased goods and balances when exiting One  A #知识点: Len (Market): List length (number of entries in the list) - IsDigit () determines whether the input is a number, TRUE is a number - Fetch list Data enumerate the For Index,item in enumerate - Print (index, item) - output highlighting "\033[31;1m%s\033[0m"% (balance) - exit the program using the Exit () method + " " -  +Market = [[1],"iphone", 5800], A[2,"Mac Pro", 12000], at[3,"Starbuck Latte", 31], -[4,"Alex Python", 88], -[5,"Bike", 1800]] -  -Balance = input ("Please input salary:") - ifbalance.isdigit (): inBalance =int (balance) - Else: toExit"illegal value, please re-enter") +  -Amount =0 the Print("Tip:type Q to exit.\n\n") *  $Shopping_cart = []Panax Notoginseng  whileTrue: -      forCommodityinchMarket : the         Print(commodity) +  AUser_choice = input ("Please enter a product number or q:\n") the  +     ifUser_choice = ="Q": -          Break $  $     ifuser_choice.isdigit (): -User_choice =Int (user_choice) -         if0 < User_choice andUser_choice <= (len) +1): theAmount + = Market[user_choice-1][2]; -             ifBalance <Amount:Wuyi                 Print("reminder:the balance is insufficient, please re-purchase.\n") the                 Continue -Shopping_cart.append (market[user_choice-1]) Wu         Else: -             Print("If you don't have the this item, please reselect it!\n") About             Continue $  - Print("List of Purchased items:\n") -  forCommodityinchShopping_cart: -     Print(commodity) A Print("Payment Amount: \033[41;1m%s\033[0m"%(amount)) +Balance-=Amount the Print("your balance: \033[31;1m%s\033[0m \ n"%balance)

Python Road Day2 Shopping Cart applet 1

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.