5/9 (un)expected character


#1

Hi,
I can't see why the ) would be an unexpected character
This is my code:

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def grades_sum(grades):
    total = 0
    for x in grades:
        total += x
    return total

print grades_sum(grades)

def grades_average(grades):
    average = grades_sum(grades) \ float(len(grades))
    return average

print grades_average(grades)

And it returns:

File "python", line 12
average = grades_sum(grades) \ float(len(grades))
^
SyntaxError: unexpected character after line continuation character

The ^ points to the second ) in float(len(grades))

Am I doing something wrong?


#2

you are supposed to do

average = grades_sum(grades) / float(len(grades))

not

average = grades_sum(grades) \ float(len(grades))

#3

Oh wow, I can't believe I did that.
Thanks!


#4

def grades_average(grades):
total = 0
for numbers in grades:
total += 1
average = grades_sum(grades) / float(len(grades))
return average
print grades_average(grades)


#5

Do you have a question?