Search code examples
pythonfor-loopappendmean

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


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)

Solution

  • 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