# Test Average and Grade – Python

## Test Average and Grade – Python

To have it print the letter grade as a user enters a score you can do something like:

``````#Calculate average
def calc_average(total):

if 90 <= grade <= 100:
return A
elif 80 <= grade <= 89:
return B
elif 70 <= grade <= 79:
return C
elif 60 <= grade <= 69:
return D
else:
return F

#Enter 5 test scores
scores = []
for i in range(1, 6):
score = int(input(Enter score {0}: .format(i)))
print Thats a(n):  + determine_score(score)
scores.append(score)

total = sum(scores)
avg = calc_average(total)

``````

The letter grade problem was that you were using total which was all the grades added up (hopefully more than 100 if you got at least a 20 on all 5 assignments), so it would always default to the else. You want to use the `avg` so that it would give you the letter grade corresponding to the average:

``````abc_grade = determine_score(avg)
``````

You can also omit the `grade = total` line because you will never use grade after making this change.

As said previously, if you want to get the correct grade letter you need to change your code from:

``````abc_grade = determine_score(grade)
``````

to:

``````abc_grade = determine_score(avg)
``````

Im not 100% sure what you meant in your last question where you asked how to display the grade letter after the average grade but if i understood you correctly you can just do this:

``````print The average grade is: %s and the grade letter of the average is: %s  % (str(avg), abc_grade)
``````

#### Test Average and Grade – Python

``````def main():
score1 = 0.0
score2 = 0.0
score3 = 0.0
score4 = 0.0
score5 = 0.0
avg = 0.0

score1 = getScore1()
score2 = getScore2()
score3 = getScore3()
score4 = getScore4()
score5 = getScore5()

findAvg = calc_average(score1, score2, score3, score4, score5)

print(------------------------------------------------)

def getScore1():
score1 = float(input(Enter score 1: ))
return score1
def getScore2():
score2 = float(input(Enter score 2: ))
return score2
def getScore3():
score3 = float(input(Enter score 3: ))
return score3
def getScore4():
score4 = float(input(Enter score 4: ))
return score4
def getScore5():
score5 = float(input(Enter score 5: ))
return score5

def calc_average(score1, score2, score3, score4, score5):
total = score1 + score2 + score3 + score4 + score5
avg = total / 5
return avg

if findAvg >= 90 and findAvg <= 100:
elif findAvg >= 80 and findAvg <= 89: