# Make a Grade Converter in Python

Grade calculator/converter is a program that assigns grades against each range of marks obtained by the student. This kind of program is often used by teachers and educational institutions to automatically calculate the grade by entering the individual score of each subject.

## Make a Grade Converter in Python

There can be multiple scenarios and criteria to calculate a student’s grade.

Here, we will make two types of grade converters. One is simple, and the other is weighted.

Here, we will make a grade converter that will calculate the grade without giving any weights to the score. Following are the steps:

• ##### Finally, we will assign a grade against each range of average scores using `if-else` conditions.

Example code:

``````#Python 3.x
total_marks=0
print("Enter Marks Obtained in 4 Subjects: ")
for i in range(1,5):
marks=int(input("Enter the marks for subject:"+str(i)+" "))
total_marks= total_marks+marks
avg_marks = total_marks/4
if avg_marks>=91 and avg_marksg<=100:
elif avg_marks>=81 and avg_marks<91:
elif avg_marks>=71 and avg_marks<81:
elif avg_marks>=61 and avg_marks<71:
elif avg_marks>=51 and avg_marks<61:
elif avg_marks>=41 and avg_marks<51:
else:
``````

Output:

``````#Python 3.x
Enter Marks Obtained in 4 Subjects:
Enter the marks for subject:1 90
Enter the marks for subject:2 80
Enter the marks for subject:3 60
Enter the marks for subject:4 70
``````

In this scenario, the grade converter will calculate the grade by adding one extra step that gives the weight to the scores obtained in exams, lab tasks, and assignments. Here, we will input the marks for exams, lab tasks, and assignments and calculate their average one by one.

Finally, we will calculate the total average score by giving weights to each score. We have defined the weightage as follows:

1. 10% of weightage belongs to the average score of assignments.
2. 20% weightage belongs to the average score of lab tasks.
3. 70% weightage belongs to the average score of exams.

After calculating the total average score, we will assign the grade against each score range.

Example code:

``````#Python 3.x
total_marks=0
exam1=int(input("Enter Marks Obtained in Exam 1: "))
exam2=int(input("Enter Marks Obtained in Exam 2: "))
avg_exam=(exam1+exam2)/2
totallab=0
totalassignment=0
for i in range(1,3):
marks=int(input("Enter Marks Obtained in Lab Task: "+str(i)+" "))
totallab=totallab+marks
avglab=totallab/2
for i in range(1,5):
marks=int(input("Enter the marks for Assignment:"+str(i)+" "))
totalassignment=totalassignment+marks
avgassignment=totalassignment/4
avg_marks=(0.1 * avgassignment + 0.7 * avg_exam + 0.2 * avglab)
if avg_marks>=91 and avg_marksg<=100:
elif avg_marks>=81 and avg_marks<91:
elif avg_marks>=71 and avg_marks<81:
elif avg_marks>=61 and avg_marks<71:
elif avg_marks>=51 and avg_marks<61:
elif avg_marks>=41 and avg_marks<51:
else:
``````

Output:

``````#Python 3.x
Enter Marks Obtained in Exam 1: 40
Enter Marks Obtained in Exam 2: 60
Enter Marks Obtained in Lab Task: 1 20
Enter Marks Obtained in Lab Task: 2 40
Enter the marks for Assignment:1 60
Enter the marks for Assignment:2 10
Enter the marks for Assignment:3 30
Enter the marks for Assignment:4 40
``````
Author: Fariba Laiq

I am Fariba Laiq from Pakistan. An android app developer, technical content writer, and coding instructor. Writing has always been one of my passions. I love to learn, implement and convey my knowledge to others.