# Sugar bush report: litres of maple sap collected each day.
SAP_PER_LITRE_SYRUP = 40 # about 40 L of sap make 1 L of syrup
def read_amounts(n):
"""Ask for n daily amounts and return them as a list of floats."""
amounts = []
for day in range(1, n + 1):
amounts.append(float(input("Day " + str(day) + " sap (L): ")))
return amounts
def total(values):
"""Return the sum of a list of numbers."""
result = 0
for v in values:
result += v
return result
def best_day(values):
"""Return the index of the largest value (first one if tied)."""
best = 0
for i in range(1, len(values)):
if values[i] > values[best]:
best = i
return best
def print_report(values, sap_total, best):
"""Print the season summary."""
print()
print("Days recorded:", len(values))
print("Total sap:", sap_total, "L")
print("Best day: day", best + 1, "with", values[best], "L")
print("Expected syrup:", round(sap_total / SAP_PER_LITRE_SYRUP, 1), "L")
def main():
amounts = read_amounts(5)
sap_total = total(amounts)
best = best_day(amounts)
print_report(amounts, sap_total, best)
main()
The complete modular program. Notice that only read_amounts uses input() and only print_report and main deal with output.