Changing amount of questions based on what the user says in Python

Viewed 39

I am trying to have a Python script that asks you how many URLs you want to input, then asks for that amount of URL. So if you say that you have 5 URLs, then it would ask you for a URL 5 times.

So it asks for URLs, you say you have X amount of URLs, so it asks for X amount of different URLs.

The only thing i can think of is the following.

while True:
    if amount > 1:
        url1 = input("Whats your first url? ")
        continue
    if amount > 2:
        url2 = input("Whats your second url? ")
        continue

Above is the only thing i can think of as, I'm relatively uninformed regarding coding and python as a language. If you have a better way of doing this, please let me know and tell me what libraries i need to either install or import, sorry if im asking alot but once again, i'm not the greatest at coding, Thanks in advance.

1 Answers

You could do something like this:

urlnum = int(input("How many urls?"))
urllist = []

for e in range(urlnum):
    urllist.append(input("Type URL %s" % str(e+1)))

then to get a url, you would use urllist[0] to get the first one, urllist[1] to get the second, etc.

Related