# Lesson #5: It's OK to be average: float question

#1

<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.>
I thought I had it right, got an error, searched to check for solutions and found a solution where setting the ‘total’ variable to a ‘float’ was done on a separate line. Copied, submitted, and passed. Wondered why my solution:
def average(numbers):
total = float(sum(numbers))
total = total / len(numbers)
wasn’t working. Went back and did this again. Think I just had a syntax error before. My question is: Is there any reason NOT to set the variable to a float and use ‘sum’ on the same line? Something that I, as a noob, cannot foresee?

<What do you expect to happen instead?>

```python

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

``<do not remove the three backticks above>``

#2

@jslattery03

You can simply do the following,

``````def average(num):
return float(sum(num)) / len(num)
``````

Any questions?