I get a user input using:
paragraphInput = input ("paste your paragraph ")
print(paragraphInput)
I get:
Line 1 of the paragraph
Line 2 of the paragraph
Line 3 of the paragraph
Line 4 of the paragraph
I would like to have displayed something like this:
This is Line 1 of the paragraph !
This is Line 2 of the paragraph !
This is Line 3 of the paragraph !
This is Line 4 of the paragraph !
So I wanted to use a for
loop but I don't know how to retrieve the line "n" of the paragraph and then to add in front of it This is
and after it !
. Is there a way of doing this ? Because the number of lines of the paragraphs will change depending on the user ...
Thanks for taking the time to read and for your help !
Python has a function to split lines of a string.
https://docs.python.org/2/library/stdtypes.html#str.splitlines
For example,
'ab c\n\nde fg\rkl\r\n'.splitlines()
returns
['ab c', '', 'de fg', 'kl'],
Then you can just iterate through this list that now has proper line breaks.
for line in paragraphInput.splitlines():
print "This is " + line + " !"
You can do
for line in paragraphInput.split('\n'):
print "This is " + line + " !"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With