Your homework assignment this week is to write a function called 'average'. it takes a list as input and returns the arithmetic average. You should assume the list only contains numbers.
It should have a docstring explaining what it does (hint: """text""").
Hints:
FOR BONUS POINTS
The bonus problem is a bit tricky but I believe in you guys. Good luck!
In [11]:
def average(L):
"""L is a list, we return the average of L (a float)"""
if not L:
return "EMPTY LIST"
return sum(L)/len(L)
In [10]:
def average2(L):
"""L is a list, we return the average of L (a float)"""
if not L:
return "EMPTY LIST"
total = 0
length = 0
for num in L:
total += num
length +=1
return total / length