Product_list = [
(' Iphone ', 8000),
(' Mac Pro ', 9800),
(' Bike ', 800),
(' Watch ', 10600),
(' Coffee ', 30),
]
Shopping_list = []
Salary = input ("Input your Salary:")
If Salary.isdigit ():
salary = Int (salary)
While True:
For Index,item in Enumerate (product_list):
Print (Index,item)
User_choice = input ("Choose to buy? >>>:")
If User_choice.isdigit ():
user_choice = Int (user_choice)
If User_choice < Len (product_list) and User_choice >=0:
P_item = Product_list[user_choice]
If P_ITEM[1] <=salary:
Shopping_list.append (P_item)
Salary-= p_item[1]
Print ("Your Current balance:", salary)
Else
Print ("Insufficient balance")
Else
Print ("Product code [%s] is not exist!" % User_choice)
elif User_choice = = ' Q ':
Print ("-----shopping list------")
Print (shopping_list)
For P in Shopping_list:
Print (P)
Print ("Your Current balance:", salary)
Exit ()
Else
Print ("Invalid option")
Python Shopping Cart program first practice