python显示为0值的值,最大最大值,名称为txt.file
我编写了代码来查找具有最小值、最大值和 0 值的材料,它仅查找最小值和最大值,但我还需要显示最小值和最大值的名称。我还需要显示 0 值。我有material.txt,其中有销售该材料的材料名称、数量、价格、公司
:
Cement,123,10000,some company
Metall,122,11000,some another company
以下是代码:
def how_many_materials():
print("Material with min val:")
with open('material.txt', "r", encoding="UTF8") as csvfile:
data = csv.reader(csvfile, delimiter=',')
minval = []
maxval = []
for i in data:
minval.append(i[1])
maxval.append(i[1])
print(min(minval))
print("Material with max val:")
print(max(maxval))
print("Materials with 0 quantity:")
I've written code to find materials with min, max and 0 values, it finds min and mav values only, but i also need to show name of min and max values. And also I need to show 0 values. I have material.txt where i have name of material, quantity, price, company
that sales this material:
Cement,123,10000,some company
Metall,122,11000,some another company
here is the code:
def how_many_materials():
print("Material with min val:")
with open('material.txt', "r", encoding="UTF8") as csvfile:
data = csv.reader(csvfile, delimiter=',')
minval = []
maxval = []
for i in data:
minval.append(i[1])
maxval.append(i[1])
print(min(minval))
print("Material with max val:")
print(max(maxval))
print("Materials with 0 quantity:")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们还需要添加材料名称:
样本输出将是:
We just need to add the material name also:
sample output would be: