# -*- coding: utf-8 -*-
# @Time : 2018-05-31 14:56
# @Author : 超人
# @Email : huxiaojiu111@gmail.com
# @File : 购物车小练习
# @Software: PyCharm
goods_list = [
['apple',30],
['car',80000],
['tesla',999999],
['computer',20000]
]
shopping_car=[]
money = input('请输入购买金额:')
if money.isdigit():
money=int(money)
while True:
for i,o in enumerate(goods_list):
print(i,o)
goods_id = input('请输入购买的商品序号[退出q]:')
if goods_id.isdigit():
goods_id=int(goods_id)
if goods_id>=0 and goods_id<len(goods_list):
goods_price=goods_list[goods_id]
money=money-goods_price[1]
if money>0:
print(goods_price)
shopping_car.append(goods_price)
else:
print('余额不足')
break
else:
print('商品编号不存在')
elif goods_id == 'q':
print('购买如下商品'.center(50,'-'))
for i in shopping_car:
print(i)
print('剩余%s元钱'%money)
break
else:
print('请输入合法字符!')