- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to create grade calculator in Python
In Academics it is a common requirement to find the grades of students after an assessment. In this article we will create a Python program which will assign the grades based on the grading criteria. Will call it A grade calculator.
Below is the grading criteria we have chosen for the program.
score >= 90 : "O" score >= 80 : "A+" score >= 70 : "A" score >= 60 : "B+" score >= 50 : "B" score >= 40 : "C"
Initialize variables and array to hold the student details including the marks obtained by individual subjects.
Define a function to accept input values on the screen and store them in the above variables.
Design a for loop to add the marks obtained in individual subjects.
Using if and elif condition design the calculator which will define the range of the marks obtained by the student and categorize the result into specific grade.
Finally define a function which will run the above functions in a specific sequence.
Run the program and input the values.
Below is the grading program as per the above approach. When we run the program it asks for various inputs. On feeding the require input, we get the final result.
class grade_calculator: def __init__(self): self.__roll_number = 0 self._Name = "" self.__marks_obtained =  self.__total_marks = 0 self.__percentage = 0 self.__grade = "" self.__result = "" def setgrade_calculator(self): self.__roll_number = int(input("Enter Roll Number: ")) self.__Name = input("Enter Name: ") print("Enter 5 subjects marks: ") for n in range(5): self.__marks_obtained.append(int(input("Subject " + str(n + 1) + ": "))) def Total(self): for i in self.__marks_obtained: self.__total_marks += i def Percentage(self): self.__percentage = self.__total_marks / 5 def calculateGrade(self): if self.__percentage >= 90: self.__grade = "0" elif self.__percentage >= 80: self.__grade = "A+" elif self.__percentage >= 70: self.__grade = "A" elif self.__percentage >= 60: self.__grade = "B+" elif self.__percentage >= 50: self.__grade = "B" elif self.__percentage >= 40: self.__grade = "C" else: self.__grade = "F" def Result(self): count = 0 for x in self.__marks_obtained: if x >= 40: count += 1 if count == 5: self.__result = "PASS" elif count >= 3: self.__result = "COMP." else: self.__result = "FAIL" def showgrade_calculator(self): self.Total() self.Percentage() self.calculateGrade() self.Result() print(self.__roll_number, "\t", self.__Name, "\t", self.__total_marks, "\t", self.__percentage, "\t", self.__grade, "\t", self.__result) def main(): gc = grade_calculator() gc.setgrade_calculator() gc.showgrade_calculator() if __name__ == "__main__": main()
Running the above code gives us the following result −
Enter Roll Number: 3 Enter Name: raj Enter 5 subjects marks: Subject 1: 86 Subject 2: 75 Subject 3: 69 Subject 4: 55 Subject 5: 92 3 Kumar 377 75.4 A PASS
- Java Program to create a Calculator
- Python Program to Create a class performing Calculator Operations
- Basic calculator program using Python program
- Basic calculator program using Python
- Broken Calculator in Python
- Golang Program to create a Class that can perform basic Calculator Operations
- Basic Calculator II in Python
- Program for EMI Calculator in C program
- Python program to display all second lowest grade student name from nested list
- Basic calculator program using C#
- Basic calculator program using Java
- Create a simple calculator using Java Swing
- C/C++ program to make a simple calculator?