python day1 (afternoon)购物清单

购物清单

#顾客给出余额

#给出商品清单

#顾客挑选商品

#给出购物清单

代码:

#!/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可用

猜你喜欢

转载自www.cnblogs.com/czh96/p/11246146.html