~1 min read • Updated Oct 12, 2025
Program Overview
This Python program receives a student’s midterm and final exam scores.
It calculates the final grade using a weighted average formula:
Final Grade = Midterm × 0.4 + Final Exam × 0.6
Python Code:
def calculate_final_grade(midterm: float, final_exam: float) -> float:
return midterm * 0.4 + final_exam * 0.6
# Read scores from user
midterm = float(input("Enter midterm score: "))
final_exam = float(input("Enter final exam score: "))
final_grade = calculate_final_grade(midterm, final_exam)
print(f"Final grade: {final_grade:.2f}")
Sample Output (input: midterm = 14, final = 18):
Final grade: 16.40
Step-by-Step Explanation:
- The user enters two scores: midterm and final exam
- The program multiplies the midterm by 0.4 and the final exam by 0.6
- It adds the two results to compute the final grade
- The final grade is printed with two decimal places
Written & researched by Dr. Shahin Siami