def getLetterGrade(score):
score = round(score)
grades = [(90, 'A'), (80, 'B'), (70, 'C'), (60, 'D'), (0, 'F')]
for i in range(len(grades)):
if score >= grades[i][0]:
return grades[i][1]
I found this for grading system. I tried to output by getLetterGrade(score)
at the end but it's not showing any result, and I don't know why.
CodePudding user response:
You'll need to pass in a variable of type int
, and make sure you call the print()
function to print out the returned result of type str
:
def getLetterGrade(score):
score = round(score)
grades = [(90, 'A'), (80, 'B'), (70, 'C'), (60, 'D'), (0, 'F')]
for i in range(len(grades)):
if score >= grades[i][0]:
return grades[i][1]
score = 75
print(getLetterGrade(score))
Output:
C
CodePudding user response:
First of all you need to indent your code over:
def getLetterGrade(score):
score = round(score)
grades = [(90, 'A'), (80, 'B'), (70, 'C'), (60, 'D'), (0, 'F')]
for i in range(len(grades)):
if score >= grades[i][0]:
return grades[i][1]
print(getLetterGrade(80))
B
then all you need to do is PRINT the result of the function. When you return in a function, that isn't printing anything out, so you need to call "print" in order to see the output to the console.