Just Weight and See error


#1


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

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

I feel like this is referencing something from the previous exercises which were done correctly according to the lesson.


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 = float(total) / len(numbers)
    return result
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return sum ((.10 * homework)(.30 * quizzes)(.60 * tests))


#2

This needs to be a comma separated list, and does not need parens on the terms.


#3

return sum (.10 * homework,.30 * quizzes,.60 * tests) throws "Oops, try again. get_average(alice) raised the following error: sum expected at most 2 arguments, got 3"


#4

It doesnt like me using sum at the end. Its an error in the way the thing checks your answer I think. If I take the sum out and just use + it works.


#5

Finally, someone who actually checked out the instructions and not the posted solutions.

Once something gets posted on these forums, others think they are solutions, then the litany of questions as to why they won't pass. It will never be the same on these boards now that somebody posted sum(). We're into a new era of problem situations that could easily be avoided by just following the instructions instead of dodging them and running to the forums for an easy answer. Where does it end? It doesn't.


#6

Except that 90% of the instructions, and interpretations of those instructions, seem quite insufficient... no templating available, or do we continue to guess our way through this?


#7

I've tried about 9 different ways to calculate the sum, based on my own intuition, and the presentations of others, and I'm still getting the same "float" error:
Oops, try again. get_average(alice) raised the following error: 'float' object is not iterable

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]
}

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

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

final = sum(.10 * homework + .30 * quizzes + .60 * tests)

return final

#8

Miight come down to indentation. You think?


#9

that's the editor of this forum...

I have since changed "float", assigning new variables, altering the sum function...

getting the same error over and over...

latest:

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

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

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return sum (.10 * homework + .30 * quizzes +.60 * tests)


#10

Have you explored the docs of this forum?


#11

seriously, why can't coding be taught like math or logic?

As in -- when you get this error, make this correction

do I have to remove all floats?
do I add in more floats?
which line is causing the problem? (it's not the calculation, it's the iteration, so, it's part of the loop)...

I'm tired of having to search through forums on every single problem, and not being able to anticipate an issue -- and these "solutions" are not actually working! still getting that error!


#12

do the docs have yet another 1000 lines of gibberish to search through?j

can someone answer the "float" problem here?


#13

removing all floats from previous lines...

same "float" error

lloyd = {
"name": "Lloyd",
"homework": [90, 97, 75, 92],
"quizzes": [88, 40, 94],
"tests": [75, 90]
}
alice = {
"name": "Alice",
"homework": [100, 92, 98, 100],
"quizzes": [82, 83, 91],
"tests": [89, 97]
}
tyler = {
"name": "Tyler",
"homework": [0, 87, 75, 22],
"quizzes": [0, 75, 78],
"tests": [100, 100]
}

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

def get_average(student):
homework = (average(student["homework"]))
quizzes = (average(student["quizzes"]))
tests = (average(student["tests"]))
return sum(.10 * homework + .30 * quizzes +.60 * tests)


#14

OK, got the answer... and it was referenced in a post above...

If any of you get a "float not iterable" error -- it's not the float, but the sum function that produces the error...

Nice -- over 20 tries... no wonder coding is so difficult, nobody knows how to teach it.


#15

In a school of self-learners, we are our own teacher. Nowhere in the instructions does it ask us to use the sum() function, so it follows it is not taught in this exercise.

'float is not iterable'

.10 * h + .30 * q + .60 * t

is a float. We cannot pass this to a function that takes an iterable.


#16

In any school we should endeavor to learn by capturing the parameters, the rules, the patterns... otherwise, we learn by guessing, and guessing and guessing... repetition is the mother of learning, so, in the former case, we build foundations, and can provide for insight, implication and VALID problem solving skills, whereas, in the latter, you learn to look up stuff on google, in forums, on cheat sheets... the former leads to strong Engineering, the latter, toward more guesswork...

So, though it is true that the sum() function was not asked for, it was provided as a potential approach, and further, it would appear not just the logical approach, but also one of the most popular... had a "rule" been introduced earlier that suggested not to use this function (or any such function that has similar restrictions) in such a context, then I would have known in advance not to waste an hour looking for the word "float", manipulating other lines, etc., etc., etc., etc., etc., etc., as I'm sure many of my fellow students (past, present and future) were forced to do as we meandered through the "guesswork" routine... further (since you've decided to open up a debate that you'll lose with me 8 days a week -- try googling that for an hour), this situation will come up again, I'm sure of it, in the next chapters, and anyone who didn't try utilizing sum() for this problem, will quite likely use it for a future problem, and get stuck, simply because you don't provide "attributes" for "functions", one of which being a list of common restrictions, and instead, you leave them with an error message that is "partly, but insufficiently" useful... too esoteric a pedagogical suggestion for you, I suppose.

Not to worry, like all other processes, I will improve upon this dynamic as well.

Regards to you Roy.

Matthew Campbell, MPM


#17

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