Home > Enterprise >  How to make an input list? [closed]
How to make an input list? [closed]

Time:09-21

I want to make a List in python using input() and For. basically what I want is this:

list = ["Data", "Data2"]
for x in list:
    print(x)

But with inputs. How can I make this?

CodePudding user response:

You can try something like this; If your input is end, loop will stop and print all of your input list

list = []
while True:
    data = input("what is your data? ")
    if data == "end":
        break
    list.append(data)

for x in list:
    print(x)

CodePudding user response:

You can try this:

data = input('Enter your data separated by space: ')
data_list = data.split(' ')
for i in data_list:
    print(i)

By the way, it is not a good idea to name your variables with builtin data structure names. In your question you used list which is a builtin name for python list.

  • Related