Put the data that is typed into the input into a list

1

I need to store the 10 numbers entered by the user into a list, only using the "for".

for c in range(0, 10):
    s = int(input())

So I would just need to know how I store each number after being typed and not just the last one, as I do currently.

    
asked by anonymous 09.12.2017 / 16:25

2 answers

2

First you define an array (s = []), then use the append function to enter the data you entered.

s = []
for c in range(0,10):
    s.append ( int(input()) )  
    
09.12.2017 / 16:40
1

The default start value of range is 0 soon to range(0,10) corresponds to range(10) which is simpler.

If you only want to read the various values, you can do it in a pythonic way using list comprehensions with:

numeros = [int(input()) for c in range(10)]

That will create a list of the 10 values that the user entered.

Documentation for range

    
09.12.2017 / 20:09