-1

I am just learning python and have almost no experience and I have hit a bit of a problem. I am learning to edit text files and I am trying to see if I can copy multi-line text into the input() function when you run it, or if you can't do that. Also I am using Replit, if that's important.

Here is my code:

example = input("Some multi-line text: ")
print(example)

I have also tried using:

example = input("""Some multi-line text: """)
print(example)

but it didn't work either.

Then I tried typing \n into shell (remember I am using Replit). That also didn't work, it just printed: example \n example

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Does this answer your question? [How to read multiple lines of raw input?](https://stackoverflow.com/questions/11664443/how-to-read-multiple-lines-of-raw-input) – ksohan Jan 28 '22 at 15:27
  • if you allow newline characters in your text how does input know that you have finished inputting text? –  Jan 28 '22 at 15:28

2 Answers2

0

You can try and use the following Python snippet for multi-line processing.

delimiter = ''
for line in iter(input, delimiter):
    <do something here>
Ryan Garvey
  • 46
  • 12
0

You can code it so that there's a while loop taking the input constantly while adding to user_text with a new line at the end. You have a condition checking for a certain keyword to stop the loop.

user_text = ""
while True:
    new_text = input()
    if new_text == "end":
        break
    user_text += f"{new_text}\n"

print(user_text)
Tharu
  • 188
  • 2
  • 14