Grade Calculator
Python Coding Problems
Conditional Statements
Loops & Iterations
Data Lists & Collections
Area Calculator
Grade Calculator
Make a Username
Voting Age
Multiplication Table
Factorial
Say Hello
Palindrome
Random Number
To-Do List
Grade Calculator
Topic: Student Grade Calculator
Description: This program prompts a user to input a student's marks for five individual subjects. It automatically computes the total marks, evaluates the overall percentage, and uses conditional statements to assign a final corresponding letter grade.
Why: Building a grade calculator teaches students how to collect multiple numerical inputs, utilize accumulator variables to find aggregates, perform basic division arithmetic for percentages, and use a multi-tiered if-elif-else structure to map numerical results to qualitative metrics.
Program Code
Copy and run the following Python code to see the grade calculator in action:
def calculate_student_grade(): print("=============================") print(" STUDENT GRADE CALCULATOR ") print("=============================") # Collecting scores for 5 subjects try: sub1 = float(input("Enter marks for Subject 1 (0-100): ")) sub2 = float(input("Enter marks for Subject 2 (0-100): ")) sub3 = float(input("Enter marks for Subject 3 (0-100): ")) sub4 = float(input("Enter marks for Subject 4 (0-100): ")) sub5 = float(input("Enter marks for Subject 5 (0-100): ")) except ValueError: print("\nError: Please enter valid numbers for marks.") return # Calculate Total and Percentage total_marks = sub1 + sub2 + sub3 + sub4 + sub5 percentage = (total_marks / 500) * 100 # Determine Grade using Multi-tier Conditional Statements if percentage >= 90: grade = "A+" status = "Passed with Distinction" elif percentage >= 80: grade = "A" status = "Passed" elif percentage >= 70: grade = "B" status = "Passed" elif percentage >= 60: grade = "C" status = "Passed" elif percentage >= 50: grade = "D" status = "Passed" else: grade = "F" status = "Failed" # Output Results Summary print("\n-----------------------------") print(" RESULTS SUMMARY ") print("-----------------------------") print(f"Total Marks Obtained : {total_marks:.2f} / 500.00") print(f"Aggregate Percentage : {percentage:.2f}%") print(f"Assigned Grade : {grade}") print(f"Academic Status : {status}") print("-----------------------------") # Execute the program calculate_student_grade()
Expected Console Output Examples
Example 1 (High Performing Profile):
=============================
STUDENT GRADE CALCULATOR
=============================
Enter marks for Subject 1 (0-100): 88
Enter marks for Subject 2 (0-100): 92.5
Enter marks for Subject 3 (0-100): 79
Enter marks for Subject 4 (0-100): 85
Enter marks for Subject 5 (0-100): 94
-----------------------------
RESULTS SUMMARY
-----------------------------
Total Marks Obtained : 438.50 / 500.00
Aggregate Percentage : 87.70%
Assigned Grade : A
Academic Status : Passed
-----------------------------
Example 2 (Failing Profile):
Enter marks for Subject 1 (0-100): 45
Enter marks for Subject 2 (0-100): 38
Enter marks for Subject 3 (0-100): 52
Enter marks for Subject 4 (0-100): 41
Enter marks for Subject 5 (0-100): 47
-----------------------------
RESULTS SUMMARY
-----------------------------
Total Marks Obtained : 223.00 / 500.00
Aggregate Percentage : 44.60%
Assigned Grade : F
Academic Status : Failed
-----------------------------
Core Syntax & Concept Breakdown
- Exception Handling (
try-except): The input capture is wrapped in atryblock. If a student inputs text instead of a number (e.g., typing "eighty"), the program catches theValueErrorand safely stops without throwing a fatal crash. - Sequential Evaluation: Python parses the conditional checks from top to bottom. If a percentage is
87.70%, it evaluates false for the>= 90check, updates true for the>= 80check, applies the grade, and exits the structural block immediately. - F-String Formatting (
:.2f): Ensures that any calculated outputs containing extended trailing decimal loops are rounded off cleanly to two places for standard report representation.
🏋️ Test Yourself With Exercises
Take our quiz on Grade Calculator to test your knowledge.
Browse Quizzes »