Python Shopping Cart program code

Source: Internet
Author: User
This article mainly for you in detail the Python shopping cart program simple code, with a certain reference value, interested in small partners can refer to

The example of this article for you to share the Python shopping cart program specific code for your reference, the specific content as follows

Code:

Created on September 4, 2017 @author: len ' product_list = [(' Robot ', 200000), (' MacPro ', 12000), (' Iphone8 ', 8888) , (' Hello world ', +),] shopping_list = [] User_salary=input ("Please enter your salary:") if User_salary.isdigit (): User_sal  ary = Int (user_salary) while True:print ("Commodity as follows:") for Index,item in Enumerate (product_list): Print       (index,item) User_choice = input ("Please enter the product number to be purchased:") if User_choice.isdigit (): user_choice = Int (user_choice) If User_choice < Len (product_list) and user_choice > -1:p_item = product_list[user_choice] If USER_SALARY&GT;=P_ITEM[1]: Shopping_list.append (p_item) user_salary-=p_item[1] Print ("Purchase goods", P_item, "Success your balance for", user_salary, "Yuan!" Else:print ("Your balance is", user_salary, "the balance is not enough to buy this item, the purchase failed!") ") Else:print (" There is no such product! ")         ") elif User_choice = =" Q ": Print ("--------shopping list-------") for I in Shopping_list:Print (i) exit () Else:print ("invalidate!!! ")

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.