7. Sending a letter Topic


#1

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)
return float(total) / len(numbers)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])

return 0.1 * average(student["homework"]) + \
0.3 * average(student["quizzes"]) + \
0.6 * average(student["tests"])

def get_letter_grade(score):
if score >= 90.0:
return "A"
elif score >= 80.0:
return "B"
elif score >= 70.0:
return "C"
elif score >= 60.0:
return "D"
else:
return "F"

print get_letter_grade(get_average(lloyd))


#2

thanks it worked although you need to do some more indention's on a few lines.


#3

Hi I have a question regarding this this stage (11.7)

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!

student = [lloyd,alice,tyler]

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

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(lloyd)

My code worked, with just "print get_letter_grade(lloyd)", but I don't know why it worked

Nowhere in the function get_letter_grade involves the other two functions, average and get_average

What is the numerical number attached to the parameter lloyd?


#4

=

I have the same question.

I think codecademy team has a invisible function for academic perpuses


#5

would the number be the numerical values in homework, quizzes and tests?


#7

this is my code but its not working

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))

it says this

Oops, try again. Your code looks a bit off, see the console window for the error message!


#8

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)
result = total / len(numbers)
return result

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


#9

Also a reply to gigaace79222 - It does not give the same grade result. It gives me a grade A instead of B. So it doesn't take the function get_average into account. Therefore I've tried to find out what value does it take into "score" so I've changed the first if >= 90 to a bigger number and it resulted with an error that gave out the value of the score: 100. So for some reason it takes 100 as Lloyd's score. I'd like to know why is the value 100. Any ideas?


#10

instead of print get_letter_grade(get_average(lloyd)),
why don't you try -
return get_average(lloyd)
print get_average(lloyd)


#11

This worked for me :slight_smile:

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

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) )

#12

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_average(lloyd)


#13

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 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(students["tests"])
mean = 0.1 * homework + 0.3 * quizzes + 0.6 * tests
return mean

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))

I'm getting an error
ERROR:

Oops, try again. get_letter_grade seems to be missing.

People,help needed please


#14

If you want to answer the exercice, you don't need to use the print, but more the :

get_letter_grade(get_average(lloyd))

Because they are asking you to call the function.

I may be wrong!


#15

The end line :" print get_letter_grade(get_letter_grade(get_average(lloyd)))"


#16

Same that's weird but some lessons have glitches :joy::joy:


#17

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!

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

def get_average(student):
homework= average(student["homework"])
quizzes =average(student["quizzes"])
tests =average(student["tests"])

return 0.1*homework + 0.3* quizzes + tests * 0.6

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

print get_letter_grade(get_average(lloyd))

i dont seem to get the mistake in this yet I can't proceed either without knowing someone pls assist


#18

Are these all guesses?
Who has actually completed the exercise?


#19

hi.guys I have this problem with whole student becomes teacher exercises, when I click on Run nothing happens, now it has been 5 days that Iā€™m stuck on sending a letter because of that,any suggestion?