How to request input data N times, and concatenate this data

1

First I asked the user to enter the amount of links he wanted to add to the file (in this case a string ), hence if he type 4, I want ask the question "Download Link:" four times for it and add all the answers to that question in a string . How do I do this?

Code:

c=input("Quantos links de download deseja colocar: ")
print("")
dw=input("Link de Download: ") 

Then it gets each response and appends to a final string as a single string .     

asked by anonymous 06.04.2015 / 04:02

2 answers

2

To make the loop is simple.

c = input("Quantos links de download deseja colocar: ")
print()
i = 0
texto = ""
while (i < int(c)):
    dw = input("Link de Download:")
    texto = texto + dw + "  "
    i = i + 1
    print()
print(texto)

See running on ideone .

Of course this implementation is very simplified, it will not do anything very useful, but from it you can improve as you need it.

    
06.04.2015 / 04:13
3

You could use for because in the case after the user type the number of times he wants to insert the links you will know how many times he has to repeat the loop, then just use lists to store the links typed . For example:

links = []
quant_links = int(input('Quantidade de Links: '))

for i in range(quant_links):
    link = raw_input('URL do link: ')
    links.append(link)

Then you only have to deal with the links inserted.

    
12.04.2015 / 18:04