5 It's Ok to be Average


#1



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


Oops, try again. average([3, 0]) returned None instead of 1.5 as expected.


Hi guys. Can you help me?


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):
    for x in numbers:
        if x == []:
            total = sum(x)
            total/(len(x))
            result2=float(total)/float((len(x)))
            return result2
            print result2
        else:
            print ' '    
    
    
            
            
average(tyler)
average(alice)
average(lloyd)


#2

You made your code way over complicated from what the instructions said.I'm not really sure why you have a for statement either. It should be a simple function.

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

#3

Thanks a lot i had resolve it!


#4

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