Student becomes the teacher



<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
the last line is shown as “incorrect syntax”

<What do you expect to happen instead?>


Add your function below!

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

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

<do not remove the three backticks above>


the last line of the code whenever i run it says that there is a syntax error there.


File “python”, line 35
return (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)
SyntaxError: invalid syntax


Make sure your return statement lines up with all your other lines of code underneath your def get_average(student)


i did that already, it just all went to the end when i copied and pasted it here.


I came across this when I couldnt figure out what I was doing wrong for “5. Its ok to be average” so thanks for clearing something up for me.

The next part is “6. Just weight and see” and I believe this is the part you are enquiring about here.

If you look at the illustration, they use apples and bananas where as we are using “student” along with “homework” and “quizzes” and “tests”.

You will need to change that to work for us and add another line in for “tests” and change the weights too.

I am going to assume the syntax error is that it does not recognise “return 0.1 * homework + 0.3 * quizzes + 0.6 * tests” those variables.

The return statement I used is:
“return 0.1 * average(student[“homework”]) + 0.3 * average(student[“quizzes”]) + 0.6 * average(student[“tests”])”

and it accepted it.

Hope I made this clear enough, you probably figured it out already anyway.


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