Why can't I use float(total) = x?


#1

I am on the "It's Okay to Be Average" portion of the section. This is the code that worked:

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

However, I initially did float(total) = sum(numbers)

Why doesnt this work? It gave me a general error in the line.


#2

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

numbers = [1,2,3,4,5,6,7,8,9,0]

average(numbers)

print average (numbers)


#3

thanks @diwakar_sharma08


#4

Hi everyone, I'm trying to get this output to 96.25, but I don't know how to do that, can anyone help?

This first line is provided for you

hrs = raw_input("Enter Hours:")
f = Float(hr)

print(f)