actually, I have a problem with this sort of input. can you tell me how can I do it in the correct way?TNX this is my code:
x,y,z=int(input()).split(" ")
but it shows this error:
invalid literal for int() with base 10:
actually, I have a problem with this sort of input. can you tell me how can I do it in the correct way?TNX this is my code:
x,y,z=int(input()).split(" ")
but it shows this error:
invalid literal for int() with base 10:
I think you are trying to read 3 space separated integers from stdin.
You are trying to split an int in the code, which will not work out.
You have to split the input and then convert the individual items to int.
See the code below,
inputs = input().split(" ")
x = int(inputs[0])
y = int(inputs[1])
z = int(inputs[2])
You can use map and do this in one line,
x,y,z = map(int, input().split(" "))
This is the closest working example to what you are trying to achieve (you need to do the integer conversion of each individual item in the list):
x,y,z = (int(num) for num in input().split(" "))
However the use of map
as suggested by other reviewers would be the preferred way to go. Also, depending on where you are utilizing this, you may wish to sanitize/validate your inputs - what do you expect to happen if the input contains 2 numbers? 4 numbers? Values which aren't numbers?