Product_list = [
(' Iphone ', 5800),
(' Mac Pro ', 9980),
(' Bike ', 800),
(' Watch ', 10600),
(' Coffee ', 31),
(' Alexpython ', 80),
]
Shop_list = []
Salary = input ("Please input your salary:")
If Salary.isdigit ():
salary = Int (salary)
While True:
For Index,item in Enumerate (product_list):
#print (Product_list.index (item), item) enumerate
Print (Index,item)
#break
User_choice = input ("Choose what 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:
Shop_list.append (P_item)
Salary-= p_item[1]
Print ("Added%s into shopping cart,your current balance is \033[31;1m%s\033[0m"% (p_item,salary))
Else
Print ("\033[42;1m your balance is left [%s]; and buy a sweater. \033[0m"% salary)
Else
Print ("Product code [%s] is not exist!") % User_choice)
elif User_choice = = ' Q ':
Print ("---------------shopping list-----------")
For P in Shop_list:
Print (P)
Print ("Your Current balance:", salary)
Exit ()
Else
Print ("Invalid option")
List of shopping carts for rookie life (Python)