# CSE 142 Python sessions # This program reads a file of gas prices for the USA and Belgium # and outputs the average gas price for each country. # # The input file format is: # 8.20 3.81 3/21/11 # 8.08 3.84 3/28/11 # ... belgium_total = 0.0 usa_total = 0.0 days = 0 f = open("gasprices.txt") for line in f: # line = "8.20 3.81 3/21/11" belgium, usa, date = line.split() # unpack the line into vars using split belgium_total += float(belgium) # b = "8.20" usa_total += float(usa) # u = "3.81" (must convert to numbers) days += 1 print("Belgium average:", belgium_total / days) print("USA average :", usa_total / days)