# Allison Obourn
# CS 115, Autumn 2021
# Lecture 31

# This program reads in gas price data from a file named gasprices.txt
# that is in the same folder as this program. Assumes that the file has
# three values per line - a Belgian gas price, a US gas price and a date.
# Prints out the average gas price in Belgium and the average gas pruce
# in the US computed using all data in the file. 


def main():
    file = open("gasprices.txt")
    data = file.read() # read everything into a single string
    data = data.split() # split the string so we have a list with each
                        # piece of data in its own spot

    sum_belgium = 0
    sum_us = 0
    for i in range(0, len(data), 3):
        sum_belgium += float(data[i])
        sum_us += float(data[i + 1])

    data_count = len(data) / 3 # divide by 3 since there were three
                               # pieces of data per date
    print("Belgium average:", sum_belgium / data_count, "$/gal")
    print("USA average:", sum_us / data_count, "$/gal")


main()
