'''
字符串的isdigit()方法
列表的enumerate方法
颜色高亮方法
'''
shopping_card=[]
goods=[('phone',5800),('bycle',1200),('book',65),('milk',53),('cup',50),('chair',200)]
salary = input('Please input your salary:')
if salary.isdigit():
salary = int(salary)
while True:
for i,j in enumerate(goods):
print(i,j)
choice = input('What do you want to buy:')
if choice.isdigit():
choice = int(choice)
if choice >= 0 and choice < len(goods):
if int(goods[choice][1]) <= int(salary):
p_item=goods[choice]
shopping_card.append(p_item)
salary = salary - int(p_item[1])
print('\033[31;1m 你买到的东西:%s,剩余金额:%s \033[0m' % (p_item,salary ))
else:
print('你的资金不足,欢迎再次光临。')
exit()
elif choice == 'q':
for i in shopping_card:
print(i)
print('你的剩余资金是:\033[31;1m%s\033[0m' % salary)
exit()
else:
print('你输入的参数错误,请输入商品编号')
else:
print('请输入数字,谢谢')