#----------------------购物车程序---------------------------
stopping_list=[
("Iphone4",1400),
("Iphone5",2500),
("Iphone6",3000),
("Iphone7",3500),
("Iphone8",4500),
("Iphonex",6500),
]
stopping_cart=[]
salary=input("Please enter your salary:")
if salary.isdigit():
salary=int(salary)
while True:
for index,item in enumerate(stopping_list):
print(index,item)
user_choice=input("Please enter the serial number of the goods you want to purchase:")
if user_choice.isdigit():
user_choice=int(user_choice)
if user_choice<len(stopping_list) and user_choice>=0:
if stopping_list[user_choice][1]<=salary:
salary-=stopping_list[user_choice][1];
stopping_cart.append(stopping_list[user_choice])
print("The goods you bought have been added to the shopping cart.")
print("Your balance is:", salary)
print()
else:
print("Your balance is not enough!")
print("Goods failed to join a shopping cart!")
print()
else:
print("The goods were not found")
elif user_choice=='q':
print("-------stopping_cart-------")
for index, item in enumerate(stopping_cart):
print(index, item)
print("Your balance is:", salary)
exit()
else:
print("Invalid command!")
2018-04-22 23:59:08