How do we read multiple inputs in one line?
For example,
91 23
and more than two values in one line.
For example,
1 45 8723
CodePudding user response:
You can reading more than 2 inputs with this map(int, input().split())
like below:
list(map(int, input().split()))
Output:
1 45 8723 # input
[1, 45, 8723]
CodePudding user response:
You can really easily do something like this:
inputs = [int(n) for n in input().split()]
You can also use a map:
inputs = map(int, input().split())
CodePudding user response:
So,
when reading 1 input in one line we can write:
x = int(input())
when reading 2 inputs in one line we can write:
x, y = map(int, input().split())
and when reading more than 2 inputs in one line we can write:
x = [int(x) for x in input().split("")]
Happy coding!