I would like to take number of subjects, then take grade letter of each by calling findGradePoint and then return GPA
def findGradePoint(g):
gradeLetter = ["A", "B", "C", "D", "F"]
gradePoint = [4.0, 3.0, 2.0, 1.0, 0.0]
for i, v in enumerate(gradeLetter):
if v==g:
gp = gradePoint[i]
return gp
def findGPA(n, ls):
totGp = 0.0
g = len(str,[ls])
for i in g:
gp = findGradePoint(i)
totGp = totGp + gp
return round(totGp / len[g],2)
I don't know how to split each value in the array to check grade point for each value and sum all the value then devide them by number count of value in array. Guide me please.
test file
import unittest
import a07
a = a07
class Test(unittest.TestCase):
def testA(self):
self.assertEqual(a.findGPA(4, ['B','B','B','C']), 2.75)
def testB(self):
self.assertEqual(a.findGPA(4, ['B','B','B','A']), 3.25)
def testC(self):
self.assertEqual(a.findGPA(7, ['C','C','C','C','B','B','F']), 2)
def testD(self):
self.assertEqual(a.findGPA(4, ['C','D','F','B']), 1.5)
def main():
unittest.main()
if __name__ == '__main__':
main()