购物车,一下午!!
解题思路
刚开始我是懵逼的,有点思路,但是写不出来,看了看教程跟着写最后出来了,我反复看了2遍。
product_list = [('iphone',5888),('macbook',12000),('meilv',998),('pen',5),('beizi',1),('text',25)]
shoping_list=[]
salary=input('pase inpu your money:')
if salary.isdigit():
salary=int(salary)
while True:
for index,item in enumerate(product_list):
print(index,item)
user_choice=input('please input product list')
if user_choice.isdigit():
user_choice=int(user_choice)
if user_choice < len(product_list) and user_choice>=0:
item_p = product_list[user_choice]
if item_p[1] <salary:
print("The product bice success")
salary = salary -item_p[1]
shoping_list.append(item_p)
print('[%s] in shopping car,your salary has \033[31;1m[%s]\033[0m'%(item_p,salary))
else:
print("\033[31;1mmyour money has [%s],need addd\033[0m"%salary)
else:
print('product code [%s] is not exist!' %user_choice )
elif user_choice == 'q':
print('-----shopping list-----')
for p in shoping_list:
print(p)
print('your salay is [%s]'%salary)
exit()
else:
print('please input reallnumber')