Taka Taka - 6 months ago 16
Python Question

connecting and separating string inputs

need help with taking inputs in a a loop like so.

example = input("enter the example !")


Then I need to add that input to one single variable and later print it all out
on separate lines EG:

loop cycle 1:
enter the example ! test1
loop cycle 2:
enter the example ! test2
loop cycle 3:
enter the example ! test3


inputs:

1. test1
2. test2
3. test3


One thing is that I am unable to use .append due to using lists in my case is
not in max efficiency. (probably will need to be taught to use \n)

Answer

you can append new line character to input function

for python2.

example = ""
for i in range(1,4):   
    example = example + str(i)+". " +raw_input("enter the example !") +"\n"
print example

for python3

example = ""
for i in range(1,4):   
    example = example + str(i)+". " +input("enter the example !") +"\n"
print (example)

output

messi@messi-Hi-Fi-B85S3:~/Desktop/soc$ python sample.py 
enter the example !text 1
enter the example !text 2
enter the example !text 2
1. text 1
2. text 2
3. text 2
Comments