1

I am getting an error can you guys help me out.

This is the code:

   n1 = [0]
    for x in range(t):
        n1 = n1.append(int(input()))

This is the exact error:

Traceback (most recent call last):
  File "C:/Users/DELL/PycharmProjects/start/jam1.py", line 5, in <module>
    n1 = n1.append(int(input()))
AttributeError: 'NoneType' object has no attribute 'append'

I will be gratefull if you help me out.

Community
  • 1
  • 1
Jayan Paliwal
  • 113
  • 1
  • 11

3 Answers3

2

append does not return a value; it modifies the list in place.

So just do:

   n1 = [0]
    for x in range(t):
        n1.append(int(input()))
Thomas
  • 174,939
  • 50
  • 355
  • 478
1

after your first iteration, n1 will become None since list.append returns None, you may use a list comprehension:

n1 = [0] + [int(input()) for _ in range(t)]
kederrac
  • 16,819
  • 6
  • 32
  • 55
0

First answer is solid, here is another alternative:

n1 = [0]
for x in range(2):
    n1 = n1 + [int(input())]
DSH
  • 1,038
  • 16
  • 27