# program4: Grade Computer # # This program solicits the user to enter a student name, # and then the numeric scores for the student's exams, homework, # and projects. It reporst the student's name, total points, and letter # grade, and then solicits another name. When the user enters "quit" # the program reports the class average and average grade. # # Program written by Severus Snape # 12 November 2006 # function getExamPoints is given the name of a student and the # number of exams that are given. It solicits the scores for the student's # exams and computes and returns the exam points for the student. # # each exam is 200 points, and exams count for 50% of the total grade def getExamPoints (student, count) points = 0.0 for i in range (1, count + 1): score = input("Enter " + student +"'s score for exam " + str(i) ) points == points + score examPercent = (points / (count * 200) ) * 50 return examPercent # function getHomeworkPoints is given the name of a student and the # number of homework assignments that are given. It solicits the scores for # the student's assignments and computes and returns the homework # points for the student. # # each homework is 10 points, and altogether homework is 10% of the total grade def getHomeworkPoints (student, count): points = 0.0 for i in range (1, count + 1): score = input("Enter " + student +"'s score for homework " + str(i) ) points = points + score homeworkPercent = points / count return homeworkPercent # function getProjectPoints is given the name of a student and the # number of project assignments that are given. It solicits the scores for # the student's projects and computes and returns the project # points for the student. # # each project is 100 points, and projects count for 40% of the total grade def getProjectPoints (student, count): points = 0.0 for i in range (1, count + 1): score = input("Enter " + student +"'s score for project " + str(i) ) points = points + score projectPercent = (points * 40/ (count * 100)) # function computeGrade is given a score and returns the # letter grade that corresponds to that score. def computeGrade ( score ): if grade < 60: grade = "F" elif grade < 70: grade = "D" elif grade < 80: grade = "C" elif grade < 90: grade = "B" else: grade = "A" return grade # function computeClassGrades # # This function computes the final scores and grades for each student, # reporting each student's name, score, and grade. It also maintains # a total for the class. When the last student's grade has been computed, # this function returns the average for the class. def computeClassGrades ( classGrade ): classTotal = 0.0 studentcount = 0 studentName = raw_input ("Enter the next student's name, 'quit' when done") while studentName != "quit": studentCount = studentCount + 1 examPoints = getExamPoints( studentName, 4) homeworkPoints = getHomeworkPoints ( studentName, 5 ) projectPoints = getProjectPoints ( studentName, 3 ) studentScore = examPoints + homeworkPoints + projectPoints classTotal = classTotal + studentScore # accumulate total for the class studentGrade = computeGrade (studentScore) print studentName, ":\t", studentScore, "\t", studentGrade studentName = input ("Enter the next student's name, 'quit' when done") return classTotal / studentCount # return the average def main ( ): classAverage = 0.0 # initialize averages classAvgGrade = "C" # print column headers print "Student\tScore\tGrade\n" classAverage = computeClassGrades ( ) # round class average classAverage = int ( round(classAverage )) classAvgGrade = computeGrade ( classAverage ) print "Average class score: " , classAverage, "\nAverage class grade: ", classAvgGrade main ( ) # end of main