# Grades1 Example # Source code file: grades1.py # Input file: grades.txt # Compute the sum of all the grades. # Important: don't forget the second # readline statement at the end of the # while loop. Without it, the while # loop is an infinite loop. sum = 0 fin = open("grades.txt", "r") # Read first line from file line = fin.readline( ) # Process lines until end of file while line != "": grade = int(line.strip( )) sum = sum + grade line = fin.readline( ) print("Sum of grades:", sum) fin.close( ) # Output: # Sum of grades: 711