Question #111360

Use the function written in the last lesson to calculate a student’s GPA. Ask them how many classes they are taking, then ask them to enter the grades for each class and if it is weighted.


Your program should then output the averaged GPA including the decimal place.


Your main program must call the function.

Expert's answer

def stGPA(student):
    a = 0
    for i in range(len(student)):
        a = a + int(student[i])
    return a / len(student)

print('How many students are in your group?')
nst = int(input())

print('How many classes You are taking?')
ncl = int(input())

students = []

for i in range(nst):
    grades = []
    for j in range(ncl):
        print('Enter grades for student',i+1)
        grades.append(input())
    students.append(grades)

for i in range(nst):
    print('student',i+1,'GPA =',stGPA(students[i]))

LATEST TUTORIALS
APPROVED BY CLIENTS