# "Float Object Not Callable", 11.8

#1

``````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
print total
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
score = (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)
return score
print score
get_average
def get_letter_grade(score):
if score >= 90:
return "A"
print "A"
if score >= 80 and score < 90:
return "B"
print "B"
if score >= 70 and score < 80:
return "C"
print "C"
if score >= 60 and score < 70:
return "D"
print "D"
else:
return "F"
print "F"
get_letter_grade
def get_class_average(students):
results = []
for student in students:
average = get_average(student)
results.append(average)
print average(results)``````

No error in the output window (which is already confusing me as there are print commands everywhere) but the codeacademy error says, "get_class_average([alice]) resulted in an error: 'float' object is not callable".

#2

``````def get_class_average(students):
results = []
for student in students:
#changed your average in new_average
new_average = get_average(student)
results.append(new_average)
print average(results)``````

#3

``````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
print total
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
score = (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)
return score
print score
get_average
def get_letter_grade(score):
if score >= 90:
return "A"
print "A"
if score >= 80 and score < 90:
return "B"
print "B"
if score >= 70 and score < 80:
return "C"
print "C"
if score >= 60 and score < 70:
return "D"
print "D"
else:
return "F"
print "F"
get_letter_grade
def get_class_average(students):
results = []
for student in students:
new_average = get_average(student)
results.append(new_average)
print average(results)``````

Well, that fixed the float problem, but now "get_class_average([alice]) should return a number" shows up in the codeacademy error window, but not the output window.

#4

@byronginn,
You have to use the comment-sign-#
in front of the lines

``````get_average
get_letter_grade``````

#5

Why? That makes no sense, I want to call those functions in order to actually get the results printed out so that I can see what's happening. Not that it's working, but even assuming that I make those functions happen, rather than just defining them, shouldn't alter the fact that something later on is failing to function correctly.

#6

``````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
print total
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
score = (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)
return score
print score
#get_average  <<=================
def get_letter_grade(score):
if score &gt;= 90:
return "A"
print "A"
if score &gt;= 80 and score &lt; 90:
return "B"
print "B"
if score &gt;= 70 and score &lt; 80:
return "C"
print "C"
if score &gt;= 60 and score &lt; 70:
return "D"
print "D"
else:
return "F"
print "F"
#get_letter_grade  <<=======
def get_class_average(students):
results = []
for student in students:
new_average = get_average(student)
results.append(new_average)
print average(results)``````

``get_class_average([alice])``

#7

here is the code I used to finish it. It is auctually just common sense.
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'])
homework = average(student['quizzes'])
homework = average(student['tests'])
return .1 * average(student['homework']) + 0.3 * average(student['quizzes']) \
+ 0.6 * average(student['tests'])

def get_letter_grade(score):
if score >= 90.00:
return "A"
elif score >= 80.00:
return "B"
elif score >= 70.00:
return "C"
elif score >= 60.00:
return "D"
else:
return "F"

print get_letter_grade(get_average(lloyd))
def get_class_average(students):
results = []
for student in students:
new_average = get_average(student)
results.append(new_average)
return average(results)

#8

No, it isn't common sense. If it were common sense, none of the students would be here and we would speak Python instead of whatever our native tongue is. I did exactly what the first post suggested by putting in the comment hashtag in front of the two commands, and am still coming up with the same error.

#9

@byronginn,
well then present the code you are using once again.....
and please try to use indentation as indentation is important in python...

edit your Post

• leave one blank-line above of your code
• select your code in the Post
• then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

#10

``````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
print total
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
score = (0.1 * homework) + (0.3 * quizzes) + (0.6 * tests)
return score
print score
#get_average  <<=================
def get_letter_grade(score):
if score >= 90:
return "A"
print "A"
if score >= 80 and score < 90:
return "B"
print "B"
if score >= 70 and score < 80:
return "C"
print "C"
if score >= 60 and score < 70:
return "D"
print "D"
else:
return "F"
print "F"
#get_letter_grade  <<=======
def get_class_average(students):
results = []
for student in students:
new_average = get_average(student)
results.append(new_average)
print average(results)``````

This is the code that I am using. Indented, formatted, copied exactly.

#11

@byronginn,
Now change the `print average(results)` in your `get_class_average()` function
to

``    return average(results)``

###=================================

``````def get_class_average(students):
results = []
for student in students:
new_average = get_average(student)
results.append(new_average)
return average(results)``````

#12

Okay, that worked. But what doesn't make sense to me is why my output field is still blank. I put 'the 'return' command in before the 'print' command, and I'm still not seeing anything. So while I've completed that part of the exercise, I haven't learned anything, or at least I'm confused as to what I just did and why it works.

#13

@byronginn,
If return statement is interpreted
it will cause an EXIT from the function...the subsequent print command is NOT interpreted anymore....
( you will have to use the print statement BEFORE the return statement )

google search
== discussions / opinions ==
python return statement explained site:stackoverflow.com
http://stackoverflow.com/questions/3881434/difference-between-returns-and-printing-in-python

== the Book ==
python return statement explained site:http://docs.python.org/2/
https://docs.python.org/2.0/ref/return.html
or
http://legacy.python.org/dev/peps/pep-0008/

#14

My bad youre right.... i guess im just to arrogent

#15

the tutorial says that i need to make a variable called 'homework'. but i ran the code w/o that variable and it worked.