Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions submissions/ENG1603884/gp calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
''''This code calculates the cgpa of students'''

print('Enter the total number of courses you offer:')
course_number = int(input())

# creates empty lists to store the inputs from the users
courses = []
grade_points = []
credit_points = []
sub_totalList = []


for a in range(course_number):#a loop that loops according to the number of courses offered


def convertGrade(grade):#function that converts the grade of the student to grade points
if grade == 'A' or grade == 'a':
return 5
elif grade == 'B' or grade == 'b':
return 4
elif grade == 'C' or grade == 'c':
return 3
elif grade == 'D' or grade == 'd':
return 2
elif grade == 'F' or grade == 'f':
return 0

print('Enter the course code:')
course = input()
courses.append(course)#adds the input to the course list
print('Enter the course credit:')
credit = int(input())
credit_points.append(credit)#adds input to the credit_points list
print('Enter your grade for the course:')
grade = input()
convertGrade(grade)#the function to convert the grades is called
sub_total = convertGrade(grade)*credit
sub_totalList.append(sub_total)#adds input to the sub_totalList list
grade_points.append(grade)#adds input to the grade_points list


gpa = sum(sub_totalList)/sum(credit_points)#gpa formula
print("Your GP is " + gpa)