This article mainly introduces the simple code of the python shopping cart program in detail, which has certain reference value. Interested friends can refer to it.
The example in this article shares the python shopping cart with you. The specific code of the program is for your reference. The specific content is as follows
Code:
''''' Created on 2017年9月4日 @author: len ''' product_list = [ ('Robot',200000), ('MacPro',12000), ('Iphone8',8888), ('Hello World',1200), ] shopping_list = [] user_salary=input("请输入你的工资:") if user_salary.isdigit(): user_salary = int(user_salary) while True: print("商品如下:") for index,item in enumerate(product_list): print (index,item) user_choice = input("请输入要购买的商品编号:") 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("购买商品",p_item,"成功您的余额为",user_salary,"元!" ) else: print("您的余额为",user_salary,"余额不足以购买此商品,购买失败!") else: print("并无此产品!") elif user_choice == "q": print("--------shopping list-------") for i in shopping_list: print(i) exit() else: print("invalidate!!!")
Rendering:
Related recommendations:
Python shopping cart user part code
The above is the detailed content of python shopping cart program code. For more information, please follow other related articles on the PHP Chinese website!