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

0

The program must receive values in a quantity specified by the user. I need a list created with these values. Why this code does 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
    
asked by anonymous 10.04.2016 / 01:53

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
    
10.04.2016 / 02:13
1

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

    
14.04.2016 / 15:37