How to play a list that skips the numbers according to the number entered

1

Preferably something that explains the answer below (without the spaces)

0

1

4

9

16

    
asked by anonymous 14.10.2017 / 17:00

2 answers

4

You can use list comprehension for this much more idiomatic question:

[ i**2 for i in range(5) ]
    
14.10.2017 / 19:33
2

If you want something that manages this result you showed in the question, just do this:

i = 0
lista=[]

while i < 5:
   lista.append((i ** 2)) 
   i += 1

Output:

[0, 1, 4, 9, 16]

and so on.

    
14.10.2017 / 17:17