Python learning-1 List for simple shopping cart, python-1
Product_list = [('iphone ', 8000 ),
('Bike', 1000 ),
('Car ', 200000 ),
('Two', 50000)]
Shop_list = []
For I, v in enumerate (product_list ):
Print (I, v)
While True:
Money = input ("Enter your money :")
If money. isdigit ():
Money = int (money)
While True:
Choice = input ("Enter the product serial number and exit the input: q :")
If choice. isdigit ():
Choice = int (choice)
If choice> = 0 and choice <len (product_list ):
Item = product_list [choice]
If money> = item [1]:
Shop_list.append (item)
Money-= item [1]
Print ("% s add to your shopping cart, % d yuan remaining" % (item, money ))
Else:
Print ("you don't have enough money, buy a wool ")
Else:
Print ("This item is not available ")
Elif choice = "q ":
Print ("------- you bought these products -------")
For j in shop_list:
Print (j)
Print ("% d" % money left)
Qw = 1
Break
Else:
Print ("invalid input ")
If qw = 1:
Break
Else:
Print ("the input is incorrect. Please enter it again ")