# GPA Calculator Implementation Using Python

Contents

## Introduction

In today’s article, we will discuss GPA calculation using python programming. We all have either the GPA system or the percentage system in our education grading system to measure a student’s performance in his/her academic session. So, to calculate the overall student performance GPA calculator is used.

## What is GPA sytem?

GPA stands for Grade Point Average. It refers to a grading system used to measure students’ performance in an academic session. It is a numerical index that summarizes the academic performance of the students in an academic year.

Different schools and other educational institutes measure GPA on different scales. For example, some measure it on a scale of 1 to 5, and some measure it on a scale of 1 to 10. This number represents the average value of all final grades earned in a course over a specific period of time.

Some organizations also use it to measure a candidate’s employability; apart from performance in the interview, these organizations also consider the GPA in academics.

## Aim of GPA Calculator

So our goal is to make a python script that takes in an array of grades as input, processes these inputs and computes the weighted average and sum, and then outputs the current grade in your class to the Terminal! How does this all work, though? So essentially, the script will accept these inputs as command-line arguments.

## GPA Calculator Code in Python

This program is designed to calculate a person’s GPA based on given point values for each letter grade. It is assumed that each class is worth one credit, and thus, all the courses are weighted the same. The given grade point values are

1. A = 4.0,
2. A- = 3.67,
3. for B+ = 3.33,
4. B = 3.0,
5. B- = 2.67,
6. for C+ = 2.33,
7. C = 2.0,
8. C- = 1.67,
9. D+ = 1.33,
10.  D = 1.0
11.  F = 0.0
```def gpa_calculator(grades):
points = 0
i = 0
return gpa
else:
return None

grades = [ 'A', 'B', 'A', 'C']

grades = ['A', 'B', 'C', 'F', 'A', 'B+']
```
```OUTPUT:-
3.25
2.7216666666666662```

### Explanation of the code

1. First, we have declared a function name as gpa_calculator with grades as its parameter.
2. Then, we had declared variables such as points to count the points as grades are entered.
3. Declared an iterable variable i starting with 0
4. Given a condition that the list of grades should not be empty. If the grades are not entered, then we will not calculate the GPA. Hence it will return None.
5. If grades are entered, then we will move to the iteration. The iteration i will start from 0 and will go up to the length of the list. For example, if the grades = [ ‘A’, ‘B’, ‘A’, ‘C’] then the length will be 4 hence the loop will iterate up to 4.
6. Now, we give the if conditions as mentioned above and the variable points will keep incrementing itself. For example, grades = [ ‘A’, ‘B’, ‘A’, ‘C’] the grade = ‘A’ then the points = 0 +4.0 =4.0 it will get stored into the point variable, similarly grade =’B’ , points = 4.0+3.0 =7.0, grade =’A’ points will now be 7.0+3.0=11.0, grade=’C’ points =11.0+2.0=13.0. Now the iteration stops thus the final value of points becomes 13.0
7. To calculate the GPA, we have the formula as points/len(grades). In our case, it becomes 13.0/4 = 3.25
8. Thus we get to print the GPA as 3.25.

### Improvements and Future

The above code was just the idea on the calculation of GPA. But our next target is to have a great user interface where users can enter the details by having the GUI.

## Create GUI GPA calculator using tkinter

```from tkinter import *
import tkinter.messagebox

points = 0
i = 0
return "Invalid"
return gpa
else:
return None

class App:
def __init__(self, parent):
self.parent = parent
self.frame_1 = Frame(parent)
self.frame_1.pack()
self.sub_count = 1
self.subs = []
self.subs.append(Entry(self.frame_1))
self.subs[self.sub_count-1].grid(row=self.sub_count-1, column=1)

self.btn_1 = Button(parent, text="Add Courses !",
self.btn_2 = Button(parent, text="Calculate GPA",
command=self.calc_CG)

self.sub_count += 1
self.subs.append(Entry(self.frame_1))
self.subs[self.sub_count-1].grid(row=self.sub_count-1, column=1)

def calc_CG(self):
for sub in self.subs:
if sub.get() != "":

root = Tk()
app = App(root)
root.mainloop()
```

OUTPUT:-

## Conclusion

It’s really nice to have a double-check sort of a tool with you to see where you are at in your class! Even if you haven’t completed or received grades yet, you could always input your grades to assignments you have completed so far, compute the weights depending on your class, and get an output!

This was so much fun, and making these little Python scripts are just the best way to get hands-on experience with Python!

If you are having any doubts or confusion feel free to comment down below. Till then keep pythoning geeks!

Subscribe
Notify of   wpDiscuz