Please explain it to me!

I would be really grateful if somebody told me how to do this!!!

Thx Teardropinfinity

Please explain it to me!

I would be really grateful if somebody told me how to do this!!!

Thx Teardropinfinity

2 Likes

Hi there, Iâd like to explain if youâd tell we to explain something, just ask me what you want to know

1 Like

def average(numbers):

#sum of the numbers

total = sum(numbers)

#making the integer a float

total = float(total)

#finding average

total = total / len(numbers)

#storing it until function is called

return total

14 Likes

on the second to last part you can do total /= len(numbers)

5 Likes

Thank you!!

2 Likes

Thanks Vidura!!

Especially for the pseudo explaining how it all works!

âŚbefore that I was sweatin it! Lol

2 Likes

What i donât understand is that they refer to the âlistâ numbers.

ofcourse there are several list with numbers. So if i set the argument of the function to numbers it will find by itself a list with numbers?

1 Like

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

6 Likes

Yeah dat makes code short thanks for showing dat

1 Like

you are welcome mateâŚ

1 Like

def get_average(student):

homework = average(student[âhomeworkâ])

quizzes = average(student[âquizzesâ])

tests = average(student[âtestsâ])

You can see dat next function calls the previous function with the lists one by oneâŚ

1 Like

or you can do it in one function in one line. See example below:

(make sure CODE ACADEMY will not accept this answer, but itâs working on my local Python 3.5.1 console)

numbers = [5, 7, 10] #this is my list of numbers

def average(numbers):

total = sum(numbers)

print (float(sum(numbers)) / len(numbers)) #I change return to print in order to see value on the console

average(numbers) #calling function

2 Likes

@ajaxsurfer81772 thanks for sharing sergeâŚ yes there are some changes in python3

2 Likes

Thanks, you wrote the code briefly and clear

2 Likes

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):

sum(numbers)

total= sum(numbers)

total = float(total)

total/len(numbers)

return total

Keep getting this error:

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

1 Like

def average(numbers):

total = 0

total = sum(numbers)

total = float(total) / len(numbers)

return total

Its OK

4 Likes