当前位置: 移动技术网 > IT编程>脚本编程>Python > python day1 (afternoon)购物清单

python day1 (afternoon)购物清单

2019年07月26日  | 移动技术网IT编程  | 我要评论

爆射裁判,英创人才,教学信息服务网

购物清单

#顾客给出余额

#给出商品清单

#顾客挑选商品

#给出购物清单

代码:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网