|
import sys
salary = int(raw_input('Please input your salary:'))
products = [
['Iphone',5800],
['Macpro',12000],
['NB Shoes',680],
['Cigarate',48],
['MX4',2500],
]
shopping_list=[]
while True :
for p in products :
print products.index(p),p[0],p[1]
choice = raw_input('Please choose sth to buy:')
if choice == 'quit':
print "you have bought below stuff:"
for i in shopping_list:
print i
sys.exit('goodbye!')
if len(choice)==0:continue
if not choice.isdigit():continue
choice = int(choice)
pro = products[choice]
if salary >= pro[1]: # means you can afford this
salary = salary - pro[1]
shopping_list.append(pro)
print 'Adding %s to shopping list,you have %s left.' % (pro[0],salary)
else :
print 'The price of %s is %s,yet your current balance is %s, so try another one!' % (pro[0],pro[1],salary)
问题:如图,本应输出3项列表中的数据,现在只输出一项,求大神解答。
|
-
演示
|