**Grade Calculator**

** **You have to write code in Python 3.This is what it looks like when it is running:

How many students?: 4

How many units?: 3

What is the name of student 1?: John

What did John get in unit 1?: 34

34 out of 100 is a Fail.

What did John get in unit 2?: 67

67 out of 100 is a Credit.

What did John get in unit 3?: 52

52 out of 100 is a Pass.

On average, John is getting a Pass.

Then after it does this for all 4 students it has to say:

The top score is (Student Name) with an average score of (Student score)

This is what I have so far but I can’t get it to go through individually.

numStudent = int (input(‘Please enter number of students: ‘))

numUnit = int(input(‘Please enter the number of units for your course: ‘))

for i in range(numStudent):

studentName = input(‘Please enter students first name: ‘)

for j in range(numUnit):

unitmark = int(input(‘what did’ + ‘ ‘ + studentName + ‘ ‘ + ‘get for unit:’))

defcalculateGrade(unitmark):

ifunitmark<= 49:

return(unitmark,”out of 100 You are failing”)

elifunitmark<= 59:

return(unitmark,”out of 100 is a Pass”)

elifunitmark<=69:

return(unitmark, “out of 100 is a Credit”)

elifunitmark<= 79:

return(unitmark, “out of 100 is a Distinction”)

elifunitmark<=100:

return(unitmark, “out of 100 is a High Distinction”)

print(calculateGrade(unitmark))

totalGrade = numUnit + unitmark

averageGrade = totalGrade / 100

print(round (averageGrade, 7))

**Solution**** **

numStudent = int(input(‘How many students?: ‘))

numUnit = int(input(‘How many units?: ‘))

data = []

defcalculateGrade(unitmark):

ifunitmark<= 49:

return ” out of 100 You are failing”

elifunitmark<= 59:

return ” out of 100 is a Pass”

elifunitmark<=69:

return ” out of 100 is a Credit”

elifunitmark<= 79:

return ” out of 100 is a Distinction”

elifunitmark<=100:

return ” out of 100 is a High Distinction”

defcalculateAvgGrade(unitmark):

ifunitmark<= 49:

return ” is getting a Fail”

elifunitmark<= 59:

return ” is getting a Pass”

elifunitmark<=69:

return ” is getting a Credit”

elifunitmark<= 79:

return ” is getting a Distinction”

elifunitmark<=100:

return ” is getting a High Distinction”

for i in range(numStudent):

name = input(‘What is the name of student ‘ + str(i+1) + ‘?: ‘)

total_score = 0

for j in range(numUnit):

score = int(input(‘What did ‘ + name + ‘ get in unit ‘ + str(j+1) + ‘?: ‘))

print(str(score) + calculateGrade(score))

total_score = total_score + score

if j == numUnit – 1:

avg = total_score / numUnit

data.append({

“name”: name,

“average”: avg

})

print(‘On average, ‘ + name + calculateAvgGrade(avg))

highest = -1

name = ”

for i in data:

if i[‘average’] > highest:

highest = i[‘average’]

name = i[‘name’]

print(‘The top score is %s with an average score of %f’ %(name, highest))