2

I want to input more than one line in Python. But when I try to and then I print the result, all it prints is the first line. Is there a way to read also the lines from the input that are below the first line?

For example:

lista=input('Insert the data here: ')
print(' ')
print(lista)

And let's say I want to input:

Hello 1 Jo

By 2 Tom

Really in 4

But it only prints the first line. Console screenshot

Any idea about how to read the other lines in the input so that I can print them afterwards?

  • 1
    You could have a while loop, but when would the program know when to print everything out? – quamrana May 20 '20 at 08:05
  • 3
    I think this will help you: [How do I read multiple lines of raw input in Python](https://stackoverflow.com/questions/11664443/how-do-i-read-multiple-lines-of-raw-input-in-python?lq=1) – tivole May 20 '20 at 08:05
  • Hint: define what will be the end of the data (empy line, dot alone on a line, etc.) and loop reading lines until you find it. – Serge Ballesta May 20 '20 at 08:06

1 Answers1

3

If you wanna read 3 line of input. You can do like this.

inputs = [input() for i in range(3)]

inputs variable will be a list

Albert Nguyen
  • 377
  • 2
  • 11