程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

python day1 (afternoon)购物清单

发布于2019-08-05 19:03     阅读(1131)     评论(0)     点赞(5)     收藏(5)


购物清单

#顾客给出余额

#给出商品清单

#顾客挑选商品

#给出购物清单

代码:

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


所属网站分类: 技术文章 > 博客

作者:大侠

链接:https://www.pythonheidong.com/blog/article/6719/660fd94c7dcdc008adca/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

5 0
收藏该文
已收藏

评论内容:(最多支持255个字符)