7/9 how to test function


I did the code and it lets me go on to the next excersize but i was wondering how i could do step 3 in the instructions and test my code.


1)Define a new function called get_letter_grade that has one argument called score. Expect score to be a number.

2)Inside your function, test score using a chain of if: / elif: / else: statements, like so:
If score is 90 or above: return "A"
Else if score is 80 or above: return "B"
Else if score is 70 or above: return "C"
Else if score is 60 or above: return "D"
Otherwise: return "F"

3)Finally, test your function! Call your get_letter_grade function with the result of get_average(lloyd). Print the resulting letter grade.

My Code:

def get_letter_grade(score):
    if(score >= 90):
        return "A"
    elif(score >= 80):
        return "B"
    elif(score >= 70):
        return "C"
    elif(score >= 60):
        return "D"
        return "F"


Calling the function just means using it. Directions want you to call it within the print function.



I tryed that but it didnt print anything to the console. is it not supposed to for that lesson?


When I run the following I got a B in the console window, which is correct.

print get_letter_grade(get_average(lloyd))

You could test this with all the students and print the number and letter grades:

print get_letter_grade(get_average(lloyd))
print get_average(lloyd)
print get_letter_grade(get_average(alice))
print get_average(alice)
print get_letter_grade(get_average(tyler))
print get_average(tyler)

Should give you this output:



I just realized i put it inside the "def get_letter_grade(score)" function


Yeah, that'd do it! Syntax kills me when programming!