According to the documentation, input
reads a line and returns it as a string ("reads a line from input"). And as you said you’re pasting all the numbers at once (and they’re one in each row), the input
stops reading when it encounters a line break and so only reads the first.
So an alternative is to make one loop and go reading the lines and adding them to the list:
print('Digite os números:')
dados = [] # lista contendo os dados digitados
while True:
linha = input()
if linha == '': # linha vazia, interrompe o while
break
dados.append(linha)
I mean, even if you do copy-Paste of the numbers, having one in each line, they will be read correctly. Each line will be read by input
and added to the list.
One detail is that we need to define some stop condition. I made it as an empty line (ie if only type ENTER), then after pasting the numbers, you’ll have to type in a ENTER.
I didn’t put the message on input
because otherwise she would be shown over and over again. But as you are pasting all the numbers at once, it makes no sense to see the same message several times, so I only printed once at the beginning, before the loop.
Once you have the list, you can print as you like. For example:
for n in dados:
print(n)
It is also worth noting that input
already returns a string, so do str(input())
is redundant and unnecessary.
Another way to read these numbers is:
dados = list(iter(input, ''))
Who basically does the same thing: iter(input, '')
creates an iterator that calls input
several times, until the returned value is ''
(the empty string). And finally, list
creates a list of the values obtained.
How are you inputando the data? Type one number, ENTER, type another, ENTER, or you copied the numbers (Ctrl-C) and pasted (Ctrl-v) all at once? I ask because you already had 4 answers (one deleted) and none solved, maybe because it is not clear how the data entry is being made...
– hkotsubo
I copied them all at once
– Awerte Aswer
however when executing and printing the first item 2030706155721618
– Awerte Aswer
I intend after printing all these elements to make a list for other purposes
– Awerte Aswer