Just Weight and See


#1


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

File "python", line 34
return 0.1 *homework + 0.3 * \ quizzess + 0.6 * tests
^
SyntaxError: invalid syntax


Sorry do you know what's wrong ? :confused:


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= sum(numbers)
    total = float(total)
    total = total / len(numbers)
    return total
students = [ tyler, alice, lloyd]
#for x in students:
    #print average(x["homework"])

def get_average(student):
    homework =average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"]
    
    return 0.1 *homework + 0.3 * \ quizzess + 0.6 * tests


#2

there is a typo... it's quizzes in the return


#3

why is there a backslash (\)?


#4

because the line ends there and I though it is needed to connect the contrubtion. I also tried the program without the backflash... It didnt change the error message:

File "python", line 34
return 0.1 *homework + 0.3 * quizzes + 0.6 * tests
^
SyntaxError: invalid syntax


#5

\ is needed if you want the code to the next line

Look at the parentheses in the line above the error message


#6

ok i was trying the code and i saw a few things wrong with it. Here are a few:
where it says tests = average(student["tests"] you forgot to put the other end bracket on the end
also for the line "return 0.1 *homework + 0.3 * \ quizzess + 0.6 * tests"
the line should be like "return 0.1 *homework + 0.3 *quizzes + 0.6*tests"
get rid of the #for x in students bit
change the quizzess to quizzes
change total= sum(numbers) to total = sum(numbers)
and also the same for homework =average(student["homework"]) change to homework = average(student["homework"])

Your welcome for the help


#7

what is the difference?


#8

well the difference is that the syntax doesn't recognize the code you are puting in. It has to have a space so it recognizes it.


#9

Thanks it works :slight_smile:
Well done


#10

your welcome boibln here to help


#11