Just weight and see



please help with this exercise. Here is my 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(["tests"])
  return (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)

but I keep getting the following error message;

get_average(alice) raised the following error: unsupported operand type(s) for +: ‘int’ and ‘str’

kindly asist

Just Weight & See.. help

How did you find a 2 year old topic? And why did you decide to add your question to this topic? Why not start a new topic? As described in the guidelines

please help me understand this, so we know to improve about the forum

As for the problem you are experiencing, what is the value of tests variable?


Sorry I’ve not had a chance to properly go through the guidelines. How did I find a 2 year old topic? Im fairly new to this forum so Im not sure I understand this question. I just searched for the lesson “Just weight and see” and various results came up.

Lastly Please what do you mean by the tests variable? Do you mean the “weights” it was multiplied by?


well, the topic you replied to:

is from may 2016, which means the topic has been inactive for a very long time. Replying to such a very old topic gives a warning:

Revive this topic?

The last reply to this topic was x days ago. Your reply will bump the topic to the top of its list and notify anyone previously involved in the conversation.

Are you sure you want to continue this old conversation?

Which should make you aware of the fact that its maybe not the best way to go. We put this warning there on purpose. Did you see this warning? Here is an image to refresh your memory:

its from a different topic, but it gives you the idea

well, here you define a variable named tests:

tests = average(["tests"])

What is the value of tests? Do you know? Are you sure its the right value?


Sorry, Im not sure I can remember if any such warning popped up. However for alice the value of tests is;

“tests”: [89.0, 97.0]

This is correct as can be seen from the code of other (learning) coders on this forum (for this lesson).


okay, lets have a look:

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

print get_average(alice)

i added a function call so the function actually executes, and a print statement to see the value of your tests variable. Looks like it doesn’t have the right value


Okay, okay, okay.

I’ve finally seen what I did wrong. I omitted student;

quizzes = average(student[“quizzes”])
tests = average([“tests”])

in tests = average([“tests”])

It should be;

tests = average(student[“tests”])

It has been corrected. The code is okay now. Thanks


yes, but i wanted you to get to this insight yourself, its will teach you far more then if i just pointed out that you should have added student, now you had to think why adding student was vital


You’re right. Thanks again