``````#定义一个嵌套列表
product_list = [('mac',9000),
('bike',2000),
('book',100),
('tasila',900000)
]
#定义购物车
shopping_card = []
shopping_card2 = []
#定义自己的金额
#判断输入的金额是否合法
if saving.isdigit():
saving = int(saving)
#让不断购买商品
while True:
#打印列表内容
for i,v in enumerate(product_list,1):
print(i,'>>>',v)
#定义购买编号
#判断输入是否数字
if choice.isdigit():
choice = int(choice)
#判断商品个数
if choice>0 and choice <= len(product_list):
#定义商品编号
Price = product_list[choice-1]
#判断商品和本金的差额
if Price[1] < saving:
saving -= Price[1]
shopping_card.append(Price)
print("你购买了%d号商品，价格是%s元,还剩%s元" %(choice,Price[1],saving))
print("-" * 30)
print("请继续选购")
print()
else:
print("余额不足，还剩%s元，请充值。" %saving)
print("-" * 30)
print("")
else:
print("商品编号不存在")

elif choice =='q':
print("******你购买了以下商品*******")
for i in shopping_card:
if i not in shopping_card2:
shopping_card2.append(i)
print(i,"x",shopping_card.count(i))
print("还剩%s元" %saving)
break
else:
print("亲，你输入了非法字符")
else:
print("亲，你输入了非法字符")``````

``````please input your money:111111
1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)

------------------------------

1 >>> ('mac', 9000)
2 >>> ('bike', 2000)
3 >>> ('book', 100)
4 >>> ('tasila', 900000)