Hey this is a demo to show some of my classmates an intro to python and coding. The code below should be able to take a list like [0,1]
and if run using the average
function would return 0.5. When run using a list the function below returns the error 'list' object has no attribute 'len'
. How would I get this function to work without removing the len()
function
def average(lst):
total = 0
for item in lst:
total += item
averageGrade= total / lst.len()
return averageGrade
How would I also get it to return a float rather than an integer