Reputation: 41
I want to get a series of strings from user and put it in a list and then print it
also i want when i put done i close the list and print it
list = []
for i in list:
list[a]=input('the name of stings:')
list.append(list[a])
a +=
print(list)
Upvotes: 0
Views: 651
Reputation: 5329
An example is shown below:
input_list = []
while True:
your_input = input('Your input : ')
if your_input.upper() == "DONE":
break
input_list.append("%s" % your_input )
print("%s" % input_list)
Output:
>>> python3 test.py
Your input : a
Your input : b
Your input : c
Your input : d
Your input : dOnE
['a', 'b', 'c', 'd']
Upvotes: 0
Reputation: 11
N = 10 # desired number of inputs
lst = [] # don't use `list` as it's resereved
for i in range(N):
lst.append(input('the name of strings: ')
print(lst)
Upvotes: 0
Reputation: 2451
You can do something like this:
n = int(input())
my_list = list()
for i in range(n):
my_str = input('Enter string ')
my_list.append(my_str)
print('You entered', my_str)
print(my_list)
Here is the sample (first line takes number, for how many times you want to take the input):
4
Enter string abc
You entered abc
['abc']
Enter string xyz
You entered xyz
['abc', 'xyz']
Enter string lmn
You entered lmn
['abc', 'xyz', 'lmn']
Enter string opq
You entered opq
['abc', 'xyz', 'lmn', 'opq']
Upvotes: 0
Reputation: 6920
Try this :
list_ = []
not_done = True
while not_done:
inp = input('name of string : ')
if inp.lower() != 'done': # Put any string in stead of 'done' by which you intend to not take any more input
list_.append(inp)
else:
break
print(list_)
Output :
name of string : sd
name of string : se
name of string : gf
name of string : yh
name of string : done
['sd', 'se', 'gf', 'yh']
Upvotes: 1