List of inputs | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

List of inputs

When I code with input() and run it, I am asked to fill the list of items what do I do?

31st Mar 2024, 3:33 PM
Art In Motion
Art In Motion - avatar
3 Answers
+ 5
@ besides of using input as mentioned by Rain , we can also do the input in one line if requested. see the samples for string and integer input. # multiple inputs for string values: (the individual input values have to be separated by a character like space or comma. the sample below uses a comma as separator. no conversion of input data is required. the result is a list of strings) inp_str = input().split(',') print(inp_str) # input: 'paul,mary,dan,liz' (input requires no quotes) # result: ['paul', 'mary', 'dan', 'liz'] # multiple inputs for integer values: (in this case, numerical values uses also a comma as separator. then each of the separated input value get mapped with the int() function, so a convertion from the default string value to an integer value is done. the result is a list of integers) inp_int = list(map(int, input().split(','))) print(inp_int) # input: 7,42,-4,70 # result: [7, 42, -4, 70]
31st Mar 2024, 6:10 PM
Lothar
Lothar - avatar
+ 2
Enter multiple inputs with seperate lines. Input don't accept list directly.
31st Mar 2024, 3:50 PM
A͢J
A͢J - avatar
+ 2
In other words, hit the Enter key after each item to go to the next line, but only hit SUBMIT after the last item to send all of them.
31st Mar 2024, 4:21 PM
Rain
Rain - avatar