Shopping Cart program, python Shopping Cart program

Source: Internet
Author: User
Tags dell xps 13 dell xps xps 13

Shopping Cart program, python Shopping Cart program

 

_ Author _ = 'xitaozi''' use the list to implement the shopping cart ''' produce _ list = [('macbook pro 100', 15.4 ), ('Think pad X1 carbon ', 10000), ('hp WASD', 7000), ('Dell xps 13', 8000)] while True: budget = input ("Enter the shopping budget:") shopping_list = [] if budget. isdigit (): budget = int (budget) while True: for (item, product) in enumerate (produce_list): print (item, product) user_choice = input ("Select product ID, add to shopping cart. Enter the letter 'q' to exit ") if user_choice.isdigit (): user_choice = int (user_choice) if user_choice <len (produce_list) and user_choice> = 0: p_item = produce_list [user_choice] if p_item [1] <= budget: shopping_list.append (p_item) budget = budget-p_item [1] print ("% s shopping cart added successfully, your budget balance is % d. "% (P_item, budget) else: print (" your budget balance is: % d And you cannot continue purchasing. "% Budget) else: print (" item number input error. Please enter it again. ") Elif user_choice = 'q' or user_choice = 'q': print (" -------- your shopping cart has the following items -------- ") for shop_item in shopping_list: print (shop_item) exit () else: print ("input error") else: print ("input error. Run the program again. ")

  

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.