# Allison Obourn
# CSC 110, Spring 2018
# Lecture 24

# Reads section data from a file and outputs the
# points each student in each section has earned
# and their grades. Points are capped at 20.
# Expects data for each section on its own line
# with attendance data for each of 5 students for
# the first section, then the second, etc. 

def main():
    file = open("sections.txt")
    lines = file.readlines()

    for i in range(len(lines)):
        print("Section", (i + 1))
        line = lines[i]
        counts = [0] * 5
        for j in range(len(line)):
            c = line[j]
            compute_count(c, j, counts)
        print("Student Points:", counts)
        compute_grade(counts)
        print()

# takes a character, an index and a list of counts as
# parameters. Adds a different number to the list at the
# index depending on what character is passed in
# Caps all values added to the list at 20. 
def compute_count(c, j, counts):
    add = 0
    if c == "y":
        add = 3
    elif c == "n":
        add = 1
    counts[j % 5] = min(counts[j % 5] + add, 20)


# takes a list of student points and calculates grades for
# those students out of 20 and prints them out rounded to one
# digit after the decimal
def compute_grade(counts):
    percents = [0] * 5
    for j in range(len(counts)):
        percents[j] = round(counts[j] / 20 * 100, 1)
    print("Student Grades:", percents)

main()
