Just Weigh and See


#1



https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/2?curriculum_id=4f89dab3d788890003000096


File "python", line 35
return .1 * homework + \ .3 * quizzes + \ .6 * tests
^
SyntaxError: unexpected character after line continuation character


I expected the program to run, should return the average for the three name lloyd, alice and tyler,


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)
    avg = float(total)/(len(numbers))
    return avg
    
def get_average(student):
    homework = float(sum(student["homework"])) / len(student["homework"])
    quizzes =  float(sum(student["quizzes"])) / len(student["quizzes"])
    tests =  float(sum(student["tests"])) / len(student["tests"])
    
    wgt_hwk_avg = .1 * homework
    wgt_quz_avg = .3 * quizzes
    wgt_test_avg = .6 * tests
    
    return .1 * homework + \ .3 * quizzes + \ .6 * tests


#2

Where you code starts to mess up is the functions.
in def average(numbers):
instead of avg = float(total)
It should be like this:

total = float(total) / float(len(numbers))
return total

Then at

def get_average(student):

Try making each part of homework like so:

lloyd_homework = average(student['homework'])

Then for lloyd_average_score, which IS needed, have it like this instead of your wgt_hwk_avg:

 lloyd_average_score = 0.1 * lloyd_homework + 0.3 * lloyd_quizzes + 0.6 * lloyd_tests
return lloyd_average_score

Then simply end it with:

return lloyd_average_score

Remove your:

 return .1 * homework + \ .3 * quizzes + \ .6 * tests

Hope this helps a lot! :grin:


#3

can someone help with this, I have read other posts, I don't just want to copy and advance.

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

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

"homework"] \ ) + 0.3 * average(student["quizzes"] + \ ) 0.6 * average(student["tests"])
^
SyntaxError: unexpected character after line continuation character


#4

Try reading my above post-It will help you without copy & paste


#5

Can someone please tell me what I'm doing wrong here? I get the following error: "Oops, try again. get_average(alice) returned 79.9 instead of the expected 91.15"

# Add your function below!
def average(numbers):
    total = sum(numbers)
    total = float(total)
    result = total / len(numbers)
    return result

students = [lloyd, alice, tyler]
def get_average(student):
    for student in students:
        homework = average(student["homework"])
        quizzes = average(student["quizzes"])
        tests = average(student["tests"])
    return (0.1*homework) + (0.3*quizzes) + (0.6*tests)

#6

At the end of get_average, include a variable called average_score, then have it equal your return statement, then return average_score.


#7

still getting the same error

# Add your function below!
def average(numbers):
    total = sum(numbers)
    total = float(total)
    result = total / len(numbers)
    return result

students = [lloyd, alice, tyler]
def get_average(student):
    for student in students:
        homework = average(student["homework"])
        quizzes = average(student["quizzes"])
        tests = average(student["tests"])
    
    average_score = (0.1*homework) + (0.3*quizzes) + (0.6*tests)
    return average_score

#8

here is my statement:

def get_average(student):
    lloyd_homework = average(student['homework'])
    lloyd_quizzes = average(student['quizzes'])
    lloyd_tests = average(student['tests'])
    lloyd_average_score = 0.1 * lloyd_homework + 0.3 * lloyd_quizzes + 0.6 *         lloyd_tests
    return lloyd_average_score

And where are your lists?


#9

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

students = [lloyd, alice, tyler]
def get_average(student):
    for student in students:
        homework = average(student["homework"])
        quizzes = average(student["quizzes"])
        tests = average(student["tests"])
    
        average_score = (0.1*homework) + (0.3*quizzes) + (0.6*tests)
    return average_score

#10

look at my stuff :smiley: above


#11

is there a way to do it with a for statement, like my code is trying to do? that way you don't have to write a formula for each student separately.


#12

I think it should work for all of them. He called the variable name Lloyd but the value isn't calling only 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)/(len(numbers))
return total

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

averagescore = (1 * homework) +  (.3 * quizzes) +  (.6 * tests)


return averagescore

Still getting this error though:

Oops, try again.
get_average(alice) raised the following error: 'dict' object is not callable

Do you know why that is?


#14

You don't have to write one for each student in this exercise, I believe


#15

hi julio, in
homework = average(student("homework"))
it should look like this:

homework = average(student['homework'])

Try that with the rest of them


#16

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.