It's Okay to Be Average- What is wrong w/ my code?


#1



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


Oops, try again. Your code looks a bit off, see the console window for the error message:
File "python", line 21
def average(number):
^
IndentationError: unexpected indent


I saw a video where someone typed it the smae way i did, but they got it right.


Replace this line with your code. 
def average(number):
     total = sum(number)
     aver = float(total)/len(number)
     return aver


#2

@orlibird
The error

point to the fact that you did not start the def at position-zero of your editor....

Remove eventual space-characters.....


#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]
}

Add your function below!

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

try this... it should help


#4

This Worked for me thanks :slight_smile:


#5


#6

That isnt working for 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]
}

Add your function below!

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

Error:

File "python", line 25
SyntaxError: 'return' outside function

What do i do?
Help needed.Thanks


#8

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