Lesson 7 Sending a letter . Stuck up badly.No help from discussion forum.Some one pl help


#1

Here is 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"
    else:
        return "F"
        

    
print get_letter_grade(get_average(lloyd))

#2

What help do you need pls?

You haven't defined a function called get_average() for you to call lloyd on it.

Please post full code, well formatted.

Thanks!


#3

As desired the full code is given below.

lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}

Add your function below!

def average(numbers):
total = sum(numbers)
total = float(total)
total = total / len(numbers)
return total

def get_average(student):
homework = average(student['homework'])
quizzes = average(student['quizzes'])
tests = average(student['tests'])
return sum((homework * 0.1, quizzes * 0.3, tests * 0.6))

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"
print get_letter_grade(get_average (lloyd))


#4


#5

My code is exactly same as your pasted image but still it is not passing.
I am again giving the whole code.

lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}

Add your function below!

def average(numbers):
total = sum(numbers)
total = float(total)
total = total / len(numbers)
return total

def get_average(student):
homework = average(student['homework'])
quizzes = average(student['quizzes'])
tests = average(student['tests'])
return sum((homework * 0.1, quizzes * 0.3, tests * 0.6))
return total

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"
print get_letter_grade(get_average (lloyd))


#6

This one was tough for me as well. After some forum searching I found some useful bits and pieces from different posts and put them together. Maybe this will work for you too. Sometimes refreshing the page helps but not all the time. Worth trying though. Anyway here's what works for me:

lloyd = {
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
alice = {
    "name": "Alice",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}

def average(numbers):
    total = float(sum(numbers))
    result = total / len(numbers)
    return result
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return (homework * 0.1) + (quizzes * 0.3) + (tests * 0.6)
    
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"
        
print get_letter_grade(get_average(lloyd))

Notice how the function def average(numbers) is different from what you have. It's condensed a bit and works nicely. See how I have total = float(sum(numbers)) and under that I've declared a new variable called result that does result = total / len(numbers). I think it organizes things better.

Now jump to where you have the function def get_average(student). Your first return statement should work without throwing sum in there. Also you shouldn't need to return total here.

Lastly make sure your indentation is right. Also they get real picky about things being exact to the directions. Like if you save something in a variable of a different name. It doesn't mean the code doesn't work but they'll fail it because it's not the name they asked for. Bogus in my opinion but that's something that happens.

Hope this helps! If not I'm still a noob so the solution would probably be out of my league.