Compiler keeps throwing AttributeError: "'NoneType' object has no attribute 'append'"

Question:

I am writing a program that takes an input of several numbers and then puts the inputted numbers in a list. The program then finds and outputs the mean average of all of the numbers in the list to the console. Whenever I run this program, I keep getting the error AttributeError: 'NoneType' object has no attribute 'append'.

What is causing this error?

episode_list= []

mather= input("Enter list:")

for number in mather:
    episode_list= episode_list.append(number)

for element in episode_list:
    total += element

final= total/ len(episode_list)

print(final)
Asked By: Darien Springer

||

Answers:

Update your first for loop with:

for number in mather:
    episode_list.append(number)

list.append does the append operation on list in place and returns None.

Also, in your second for loop, you need to do:

for element in episode_list:
    total += int(element)
    #        ^ Type-cast the value to `int` type 
Answered By: Moinuddin Quadri

episode_list.append(number) alone is enough

And that is because list.append is done in-place.

Answered By: Tony Tannous
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.