-1

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)
Darien Springer
  • 467
  • 8
  • 17
  • 2
    `list.append` appends to the list and returns `None`, doing `episode_list = episode_list.append(number)` appends to the list then assigns the variable to `None` hence the error. – Tadhg McDonald-Jensen Dec 16 '16 at 23:28

2 Answers2

2

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 
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126
1

episode_list.append(number) alone is enough

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

Tony Tannous
  • 14,154
  • 10
  • 50
  • 86