PYTHON PYTHON PROGRAMMING write a grading progtam for a class with the following
ID: 3732751 • Letter: P
Question
PYTHON
PYTHON PROGRAMMING
write a grading progtam for a class with the following grading policies:
a. there are two quizzes, each graded on the basis of 10 points
b. there is one midterm exam and one final exam, each graded on the basis of 100 points
c. The final exam counts for 50% of the grade, the midterm counts for 25% and the two quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores. They should be converted to a percent before they are averaged in).
any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less then 80) is a C, any grade of 60 or more (but less than 70) is a D, any grade below 60 is an F.
The program will read in the student's score (two quiz and two exams) and output the student's record, which consists of two quiz and two exam scores as well as the student's average numeric score for the entire course and the final letter grade.
You will write this program in the following two way (You will hand in TWO SEPARATE programs):
1. write this program so that user can enter grades for as many students as he/she wants (using while loop).
2. Include following validatios:
a. Do NOT accept less than 0 and greater than 10 for any of the two quizzes
b. Do NOT accept less than 0 and greater than 100 for midterm and final exams.
Explanation / Answer
class Student:
def __init__(self, quizOne, quizTwo, midTerm, finalExam):
self.__quizOne = quizOne
self.__quizTwo = quizTwo
self.__midTerm = midTerm
self.__finalExam = finalExam
def get_quiz_one(self):
return self.__quizOne
def get_quiz_two(self):
return self.__quizTwo
def get_mid_term(self):
return self.__midTerm
def get_final_exam(self):
return self.__finalExam
def set_quiz_one(self, value):
self.__quizOne = value
def set_quiz_two(self, value):
self.__quizTwo = value
def set_mid_term(self, value):
self.__midTerm = value
def set_final_exam(self, value):
self.__finalExam = value
def calculate(self):
quizMarks = self.get_quiz_one() + self.get_quiz_two()
quizMarks = quizMarks*5
totalPercent = 25*(quizMarks) + 50*(self.get_final_exam()) + 25*(self.get_mid_term())
return float(totalPercent)/100
def grade(self, value):
if(value >= 90):
return 'A'
elif (value >=80):
return 'B'
elif(value >=70):
return 'C'
elif value >=60:
return 'D'
else:
return 'F'
line = raw_input("Enter Student Marks Give input as '#' to exit or any other key to continue")
studentList = []
try:
#While loop for students Marks untill # is given
while line!='#':
quizOne = input("Enter quiz 1 marks (0 - 10)")
while quizOne > 10 or quizOne < 0:
quizOne = input("Quiz 1 is conducted for 10 Marks,So input should be 0 - 10 ")
quizTwo = input("Enter quiz 2 marks(0 - 10)")
while quizTwo > 10 or quizTwo < 0:
quizTwo = input("Quiz 2 is conducted for 10 Marks,So input should be 0 - 10 ")
midTerm = input("Enter mid Term marks(0 - 100)")
while midTerm > 100 or midTerm < 0:
midTerm = input("Mid Term is conducted for 100 Marks,So input should be 0 - 100")
finalExam = input("Enter final Exam marks (0 - 100) ")
while finalExam > 100 or finalExam < 0 :
finalExam = input("Final Exam is conducted for 100 Marks, So input should be 0 - 100")
obj = Student(quizOne, quizTwo, midTerm, finalExam) #Student Object with all marks
studentList.append(obj)
line = raw_input("Enter Student Marks Give input as '#' to exit or any other key to continue")
except NameError:
print "Input should only be Integer , Please Try Again"
except:
print "Exception Occured!!!"
if len(studentList)!=0:
print "------Student Records-------"
print "Quiz 1 Quiz 2 Mid Term Final Exam Average Grade"
else:
print "No Records"
# Iterating Over the Student List
for obj in studentList:
#Calculating total Percent of student
totalPercent = obj.calculate()
#Calculating gade based on Percentage
grade = obj.grade(totalPercent)
#Printing Student Records
print "{:6d}{:10d}{:12d}{:15d}{:11.2f}{:>7s} ".format(obj.get_quiz_one(),obj.get_quiz_two(),obj.get_mid_term(),obj.get_final_exam(),totalPercent,grade)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.