How to realize Shopping cart by python
This article is about how python implements a shopping cart. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
#! / usr/bin/env python
#!-coding:utf-8
# Author:Eric
My_salary = input ("Input your salary:")
If My_salary.isdigit ():
My_salary = int (My_salary)
Else:
Exit ("Invaild data type...")
Welcome_msg = 'Welcome to Eric Shopping mall'.center'
Print (welcome_msg)
Exit_flag = False
Product_list = [
('Iphone',5800)
("Mac Air", 8000)
("Mac Pro", 9000)
(XiaoMi 2, 19.9)
("Coffee", 30)
("Tesla", 820000)
("Bike", 700)
(Cloth, 200),]
Shop_car = []
While exit_flag is not True:
# for product_item in product_list:
# pawname.pamphlet price = product_item
Print ("product list" .center (50jinzhuyu'))
For item in enumerate (product_list): # returns the subscript in the list. Enumerated function
Index = item [0]
P_name = item [1] [0]
P_price = item [1] [1]
Print (index,'.',p_name,p_price)
# print (len (product_list))
User_choice = input ("[Q = quit,c=check] What do you want to Buy?:")
If user_choice.isdigit (): # must be to choose a product. User_choice = int (user_choice) if user_choice < len (product_list): p_item = product_ list [user _ choice] if p_item [1]