Change the line. Refer to python docs for inline len . The built-in len calculates the number of elements in a sequence. Since a list is a sequence, an inline can work on it.
averageGrade= total / lst.len()
to
averageGrade= total / len(lst)
The reason it fails with the error 'list' object has no attribute 'len' is because the list data type has no method named len . Refer to python docs for list
Another important aspect is that you do integer division. In Python 2.7 (which I assume from your comments), unlike Python 3, returns an integer if both operands are integers.
Change the line
total = 0.0
to convert one of your operands from divisor to float.
Abhijit
source share