Python test Average Calculator returen error 'list' object has no attribute 'len'
Change the line
averageGrade= total / lst.len()
to
averageGrade= total / len(lst)
Refer the python docs for the built-in len. The built-in len calculates the number of items in a sequence. As list is a sequence, the built-in can work on it.
The reason it fails with the error 'list' object has no attribute 'len'
, because, list
data type does not have any method named len
. Refer the python docs for list
Another important aspect is you are doing an integer division. In Python 2.7 (which I assume from your comments), unlike Python 3, returns an integer if both operands are integer.
Change the line
total = 0.0
to convert one of your operand of the divisor to float.
or by changing
averageGrade= total / lst.len()
to:
averageGrade= total / lst.__len__()