7/9 Sending A Letter


#1

I typed in this script and it gives me an error saying "Oops, try again. get_letter_grade seems to be missing"

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

Obviously, I mentioned "get_letter_grade" in the function. Why is it giving me this error?


#2

Hi @alpakadesigns ,

Did you indent the entire get_letter_grade function, including the header, by mistake? If you do this, the function will not be recognized in the global scope, and you will get the message that you got ...

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return 0.1 * homework + 0.3 * quizzes + 0.6 * tests
    
    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"
        else:
            return "F"

The indentation should be like this ...

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return 0.1 * homework + 0.3 * quizzes + 0.6 * tests
    
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"
    else:
        return "F"

In your code, change this ...

return "E"

... to ...

return "F"

#4

Oh mah gawd. It worked. :smile:


#5

Dude, you made my day. hugs hugs