python day1 (afternoon)购物清单
程序员文章站
2022-04-30 22:23:35
购物清单 #顾客给出余额 #给出商品清单 #顾客挑选商品 #给出购物清单 代码: ......
购物清单
#顾客给出余额
#给出商品清单
#顾客挑选商品
#给出购物清单
代码:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
salary = int(input('plaese input your salary:'))
product_list = [[1, ['bike', 1500]], [2, ['iphone', 8000]], [3, ['mac pro', 15000]], [4, ['fruit', 100]]]
shopping_list = []
while true:
for i in product_list:
print(i)
p = int(input('plaese pick commodity(product id):'))
if salary >= product_list[p-1][1][1]:
salary = salary - product_list[p-1][1][1]
shopping_list.append(product_list[p-1][1])
k = input('do you want to shop something:')
if k[:1] in 'y':
continue
else:
break
else:
print('your balance is not enough')
break
count = 0
for x in shopping_list:
print(x)
count += x[1]
print('''
sum of consumption:{}
balance:{}
''' .format(count, salary))
pycharm python3.7可用
上一篇: 拯救夫妻感情的神器
下一篇: CSRF_TOKEN