Assignment: Post
Created on 16 June 2020
Author:
"""
def average_cost(lines):
total_cost = 0
total_weight = 0
for line in lines:
parts = line.split()
for part in parts:
weight = int(part)
if weight <= 25:
total_cost += 4
elif weight <= 100:
total_cost += 7
elif weight <= 250:
total_cost += 10
total_weight += weight
average = total_cost / total_weight * 1000
return average
lines = []
file = open("post.in.txt")
for line in file:
lines.append(line)
average = average_cost(lines)
print('A kilogram costs on average: %.0f coins' % average)