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>=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!!! ")
: