from sys import *
DEBUG = True
def count_attendence(line):
attended = [0] * 5
for i in range(len(line)):
if(line[i] == "1"):
attended[i % 5] += 1
return attended
def compute_points(attended):
points = [0, 0, 0, 0, 0]
for i in range(len(attended)):
points[i] = min(20, 3 * attended[i])
return points
def compute_grades(points):
grades = [0.0, 0.0, 0.0, 0.0, 0.0]
for i in range(len(points)):
grades[i] = 100.0 * points[i] / 20.0
return grades
def results(attended, points, grades, output):
output.write ("Sections attended: " + str(attended) + "\n")
output.write ("Sections scores: " + str(points) + "\n")
output.write ("Sections grades: " + str(grades) + "\n\n")
# main
file = open("sections.txt")
if DEBUG: output = stdout
else: output = open("sections_output.txt", "w")
for line in file:
attended = count_attendence(line)
points = compute_points(attended)
grades = compute_grades(points)
results(attended, points, grades, output)
if output != stdout: output.close()
file.close()