Search code examples
python-3.xwhile-loopappendattributeerror

How to fix this AttributeError in Python?


This is my code:

m1=int(input("¿Cuantas filas tiene la matriz 1?: "))
contador_filas1=1
f1=[]
while contador_filas1<=m1:
  print("Dame los valores de la fila",contador_filas1,"(separados por comas):")
  f1.append=input()
  contador_filas1=contador_filas1+1
print(filas1)

What can I do? If I want to do a list, with the values given by f1.append but when I run the program the shell is launching me this notice:

Traceback (most recent call last):
  File "C:\Users\Susana\Desktop\Matrices.py", line 10, in <module>
   f1.append=input()
AttributeError: 'list' object attribute 'append' is read-only

Solution

  • You need pass the result of input as argument to append

    f1.append(input())