Product_list = [
("Iphone", 6000),
("Mac Pro", 12800),
("Bike", 600),
("Watch", 8000),
("book", 24),
("Offee", 35),
]
Shopping_list = ()
Salary = (Input ("Please enter your purchase:"))
If Salary.isdigit (): # To determine if the value entered is numeric, then continue
salary = Int (salary)
While True:
For item in Product_list:
Print (Product_list.index (item), item) # Prints the list's subscript and list
User_choice = input ("Please enter the item number you want to purchase:")
If User_choice.isdigit ():
user_choice = Int (user_choice)
Print ("Input error, please re-enter")
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) # is not called. Append, it's drunk.
Salary-= p_item[1]
Print ("The item you purchased was successfully purchased, the balance is still remaining%s"% (p_item[0],salary))
Else
Print ("Not enough balance to buy, please re-select it!")
elif User_choice = = "Exit":
Print ("Exit successful, welcome next time")
Print ("----info of shoppint_list")
For P in Shopping_list:
Print (P)
Print ("Your balance is still remaining", salary)
Print (shopping_list)
Exit ()
Else
Print ("Input value is wrong, please reenter")
Print ()
Python Basics Job 1----shopping cart little Practice