Python Program for Mark Entry and Grade Calculation

Python Program for Mark Entry and Grade Calculation

In this article, we will go through a Python program designed to input marks for five subjects and display the grade based on the overall percentage. This example is designed for educational purposes and can be easily modified to fit different grading criteria or different subject counts.

Python Code for Mark Entry and Grade Calculation

To create a Python program that takes in the marks of 5 subjects and displays the grade, follow the steps below. We will define a function that calculates the average marks and assigns a grade based on the average. Then, we will prompt the user to input marks for each subject and print the results.

Code Implementation

```python # Function to calculate average marks and assign grade def calculate_grade(subject_marks): total_marks sum(subject_marks) average_marks total_marks / len(subject_marks) if average_marks > 90: return 'A ' elif average_marks > 80: return 'A' elif average_marks > 70: return 'B' elif average_marks > 60: return 'C' elif average_marks > 50: return 'D' else: return 'F' # Initialize list to store marks for 5 subjects subject_marks [] # Loop to prompt user for marks of each subject for i in range(5): subject_(int(input(f'Enter Marks of Subject {i 1}: '))) # Call the function to calculate grade grade calculate_grade(subject_marks) # Print the marks and the grade print(f'_______________Information Gathered________________ Marks: {subject_marks} Percentage of Student is: {sum(subject_marks)/5} Grade is: {grade}') ```

How the Program Works

1. **Function Definition**: The `calculate_grade` function takes a list of marks as input. It calculates the average and determines the grade based on a simple grading scale that we have defined. 2. **User Input**: The program asks the user to enter the marks for five subjects. We use a loop to collect these marks. 3. **Calculation and Output**: After collecting the marks, the program calculates the grade using the `calculate_grade` function and prints the marks and the calculated grade.

Example Usage

```python # Example input and output Enter Student Name : Muhammad Faizan Enter Student Roll no : 134492 Enter Marks of Mathematics : 77 Enter Marks of English : 77 Enter Marks of Computer : 35 Enter Marks of Islamiat : 40 Enter Marks of Urdu : 78 _______________Information Gathered________________ Marks: [77, 77, 35, 40, 78] Percentage of Student is: 68.6 Grade is: D ```

This is a basic example. You can modify the grading scale to fit your specific needs, or add more subjects to the program as needed.

Conclusion

This Python program demonstrates how to take in marks from the user, calculate the average, and determine the grade based on the average marks. This is a practical application of Python programming that can be adapted to various educational environments. Whether you are a teacher, a student, or a parent, this program can help you easily handle and understand student performance.

Related Keywords

Python programming Mark entry Grade calculation Student marks