# Gradebook # # This program allows the user to enter grade information for a class of students and # calculate final grades. It reports student's names, total points, and letter grades. It # also report s the class average and the average grade for the class. # # Written by Bart Simpson # 18 November 2011 # computeGrade # # this function is given a score and returns the equivalent letter grade # def computeGrade(score): if score >= 90: grade = "A" elif score >= 80: grade = "B" elif score >= 70: grade = "C" elif score >= 60: grade = "D" else: grade = "F" return grade # end of computeGrades # getExamPoints # # This function is given a student name and solicits the user to enter # four exam scores for the student. It then computes the number # of points the exams earn toward a final grade. # def getExamPoints ( student ): points = 0.0 for i in range (1,5): points = points + input ("Please enter " + student + "'s score for exam " + str (i) + "> " ) return points*50.0 / 800 # end of getExamPoints # getHomeworkPoints # # This function is given a student name and solicits the user to enter # five homework scores for the student. It then computes the number # of points the exams earn toward a final grade. # def getHomeworkPoints ( student ): points = 0.0 for i in range (1,6): points = points + input ("Please enter " + student + "'s score for homework " + str (i) + "> " ) return points / 5.0 # end of getQuizPoints # getProjectPoints # # This function is given a student name and solicits the user to enter # three project scores for the student. It then computes the number # of points the exams earn toward a final grade. # def getProjectPoints ( student ): points = 0.0 for i in range (1,4): points = points + input ("Please enter " + student + "'s score for project " + str (i) + "> " ) return points * 40.0 / 300 # end of getProjectPoints def main ( ): classAverage = 0.0 # initialize averages classAvgGrade = "C" studentScore = 0.0 classTotal = 0.0 studentCount = 0 gradeReport = "\n\nStudent\tScore\tGrade\n============================\n" studentName = raw_input ("Enter the next student's name, 'quit' when done> ") while studentName != "quit": studentCount = studentCount + 1 examPoints = getExamPoints (studentName) hwPoints = getHomeworkPoints (studentName) projectPoints = getProjectPoints (studentName) studentScore = examPoints + hwPoints + projectPoints studentGrade = computeGrade (studentScore) gradeReport = gradeReport + "\n" + studentName + ":\t%6.1f"%studentScore+"\t"+studentGrade classTotal = classTotal + studentScore studentName = raw_input ("Enter the next student's name, 'quit' when done> ") print gradeReport classAverage = int ( round (classTotal/studentCount) ) # call the grade computation function to determine average class grade classAvgGrade = computeGrade ( classAverage ) print "Average class score: " , classAverage, "\nAverage class grade: ", classAvgGrade main ( ) # Launch