# Allison Obourn
# CS 115, Autumn 2021
# Lecture 31

# This program reads in class schedule voting data from a file named times.txt
# that is in the same folder as this program. Assumes that the file contains
# votes for Morning, Afternoon and Evening only. Computes and prints the count
# of how many people voted Morning, how many voted Afternoon and how many
# voted Evening. Then prints out all votes on one line with no spaces.

# takes a vote value (Morning, Afternoon or Evening) and returns the index in
# the list that stores the count of votes for that value
def get_index(value):
    if value == 'Morning':
        return 0
    elif value == 'Afternoon':
        return 1
    else:
        return 2

def main():
    file_name = "times.txt"
    file = open(file_name)

    # read the contents of the file into a string and then split on white space
    # since some lines have multiple votes and we want to process them
    # separately
    lines = file.read()
    votes = lines.split()

    # list of length 3 since we are counting 3 different values
    counts = [0] * 3
    
    for i in range(0, len(votes)):
        index = get_index(votes[i])
        counts[index] += 1

    print(counts)

    # builds up a string of all vote text with no spaces in between so we can
    # print it on one line with no spaces
    result = ""
    for i in range(0, len(votes)):
        # instead of building up a string with concatenation and printing it,
        # we could use the line below to just print it directly vote by vote
        # in our loop.
        # print(votes[i], end="")
        result = result + votes[i]

    print(result)

main()
