Trying to use a for loop to calculate the mean of a list as I want to practice.
This code is returning 4, 5, and 1 with the test cases. Can someone tell me what I'm doing wrong please?
def list_mean(p):
total = 0
i = 0
if i < len(p):
for t in p:
total = total + p[i]
i += 1
return i
mean = i / len(p)
return mean
print list_mean([1,2,3,4])
>>> 2.5
print list_mean([1,3,4,5,2])
>>> 3.0
print list_mean([2])
>>> 2.0