Why does the following code print 'None' instead of the list?

Asked

Viewed 226 times

0

The program must receive values, in a quantity specified by the user. I need a list to be created with these values. Why does this code not work?

quantidade = int(raw_input())
inicio = 0
lista1 = list()
while inicio < quantidade:
    valor = int(raw_input())
    inicio = inicio + 1
    lista2 = lista1.append(valor)
print lista2

2 answers

1


quantidade = int(raw_input())
inicio = 0
lista1 = list()
while inicio < quantidade:
    valor = int(raw_input())
    inicio = inicio + 1
    lista1.append(valor)
print lista1

1

You are assigning the return of the append method to a variable and printing, but this method returns nothing. append only adds a value at the bottom of the list. The correct thing is to do as @M8n replied.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.