0
Inputs and lists
How do I create a function that insert every input in a list, then with an imput like 'End', the output prints the list with the elements inserted?
2 ответов
+ 1
Depending on how your program is structured (if it actively takes input or all at once) - you'll simply have a set of conditional statements to check if the input is 'end', else append the given value go an empty list, or append each individual character in the string.
So something like this that actively asks for values:
active = True
alist = []
while active:
user_in = input(">>> ")
if user_in == 'end':
active = False
else:
alist.append(user_in)
print(alist)
You can also use a break instead of the active variable. Always a thousand different answers to a problem.
0
That's great, thank you