# # Author: James Tam # Version: March 3, 2010 # # The second version of a program that tracks the grades for a class. # # Global constant to specify the size of the list. CLASS_SIZE = 5 # Step through the list an element at a time and get the user to input the # grades. def read (classGrades, average): total = 0 for i in range (0, CLASS_SIZE, 1): # Because list indices start at zero add one to the student number. temp = i + 1 print "Enter grade for student no.", temp, ":", classGrades[i] = input () total = total + classGrades[i] average = total / CLASS_SIZE return (classGrades, average) # Traverse the list and display the grades. def display (classGrades, average): print print "GRADES" print "The average grade is", average, "%" for i in range (0, CLASS_SIZE, 1): # Because array indices start at zero add one to the student number. temp = i + 1 print "Student no.", temp, ":", classGrades[i], "%" # MAIN FUNCTION # Variable initializations i = 0 temp = 0 average = 0 # Creates a variable that refers to the list with no elements classGrades = [] # Create a list with 5 elements with each element initialized to zero # Within the body of the loop create a new list element that contains 0 # and append / add it to the end of the list. for i in range (0, CLASS_SIZE, 1): classGrades.append(0) classGrades, average = read (classGrades, average) display (classGrades, average)