# 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 reports 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 # 19 November 2011 # ####################################################### # getPoints is a generic function for obtaining the scores for # a category of graded work and computing the percentage # points earned. # # Arguments are: student (student name), # count (the number of instances of the work) # category (the name of the category, such as "exam") # value (the number of percentage points possible) # scoreRange (the maximum score possible for each instance) def getPoints (student, count, category, value, scoreRange): points = 0.0 for i in range (1, count + 1): score = input("Enter " + student +"'s score for " + \ category + " " + str(i) + " >>> ") points = points + score percent = points * value / (count * scoreRange) return percent # end of function getPoints # function computeGrade is given a score and returns the # letter grade that corresponds to that score. def computeGrade ( score ): if score < 60: grade = "F" elif score < 70: grade = "D" elif score < 80: grade = "C" elif score < 90: grade = "B" else: grade = "A" return grade # end of function computeGrade def main ( ): classTotal = 0.0 studentCount = 0 reportBody = "\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 = getPoints( studentName, 4, "exam", 50, 200 ) homeworkPoints = getPoints ( studentName, 5, "homework", 10, 10 ) projectPoints = getPoints ( studentName, 3, "project", 40, 100 ) studentScore = examPoints + homeworkPoints + projectPoints studentGrade = computeGrade (studentScore) reportBody = reportBody + studentName + ":\t" + \ str(studentScore) + "\t"+ studentGrade + "\n" classTotal = classTotal + studentScore studentName = raw_input ( \ "Enter the next student's name, 'quit' when done >>> ") # end while if studentCount > 0: classAverage = int ( round (classTotal/studentCount) ) classAvgGrade = computeGrade ( classAverage ) print reportBody print "Average class score: " , classAverage, \ "\nAverage class grade: ", classAvgGrade else: print "No data to report" main ( ) # launch program