I have a simple question, I just want to store an input of multiple lines into an array using python, note that the first line of the input is telling me how many lines there will be, so if the first line of the input is 4, the whole input will be of 5 lines in total.
Example:
input:
4
1
2
3
4
output:
[1, 2, 3, 4]
I tried using n = list(map(int, input())) however when I print the whole list it only stores the first line of the input, and I need all the values.
Thank you.
input()will be called only once this way, you will need some kind of an explicit loop for this.input()reads a single line from the standard input, yes? So of course anything you do with a single line of input will only process that line of input. You need to come up with a step-by-step process that handles multiple lines of input. Yes? So, think it through logically. What is the first step in this process: you read the first line, and it tells you how many more lines to process. Yes? So implement that. Now that you have that number, do you see how to proceed with the rest of the input?