Search code examples
pythonpython-3.xlistinputuser-input

Extracting user input in 2 different arrays


The user input is:

7
-3 10
-1 8
-0.5 -1
0.5 1
0.5 -2
0 -5
1 -5 

And the output I want to get is 2 lists A and B that would print the in the following format:

[7, -3, -1, -0.5, 0.5, 0.5, 0, 1]
[10, 8, -1, 1, -2, -5, -5]

It would be really helpful if I could get the code for this in python.


Solution

  • Is that what you want?

    INPUT_COUNT = 8
    
    FIRST_INPUTS = []
    SECOND_INPUTS = []
    for _ in range(INPUT_COUNT):
        result = input().split()
        try:
            FIRST_INPUTS.append(float(result[0]))
            SECOND_INPUTS.append(float(result[1]))
        except IndexError:
            pass