您的位置:首页 > 其它

3.购物车

2017-08-11 10:44 176 查看
product_list = [
('iphone', 5800),
('Mac Pro', 9800),
('Bike', 800),
('Watch', 10600),
('Cofee', 31),
('python', 120)
]
shopping_list = []
def panduan(string):
s = str(string)
if s.count('.') == 1:
sl = s.split('.')
left = sl[0]
right = sl[1]
if left.isdigit() & right.isdigit():
return True
else:
return False
elif s.isdigit():
return True
else:
return False

salary = input("Input your salary:")
if panduan(salary):
salary = float(salary)
while True:
for index, item in enumerate(product_list):
print(index, item)
user_choose = input("请输入商品编号:")
if user_choose.isdigit():
user_choose = int(user_choose)
if user_choose < len(product_list) and user_choose > 0:
s = product_list[user_choose]
if s[1] <= salary:
shopping_list.append(s)
salary -= s[1]
print('added %s into your shopping cart ,your balance is \033[31;1m%s\033[0m' % (s[0], salary))
else:
print('your salary can not affrond')
else:
print('您输入的商品编号不存在...')
elif user_choose == 'q':
print('----------shopping list-------------')
for i in shopping_list:
print(i)
print('余额:', salary)
print('------------------------------------')
exit()
else:
print('无效编号!!!')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: