Search code examples
pythonpython-3.xinputintegervalueerror

Multiple int input in same line python


I want to take multiple integer inputs in the same line. I know I can take str input and then convert them into integer in the next line but is there any way I can do it in the same line.

I have tried this:

x,y = int(input("->")).split()
print(x,y)

I am getting this error : ValueError: invalid literal for int() with base 10


Solution

  • You messed up with parenthesis (split works on string not int) then you expect a tuple for x,y = ...

    the solution is:

    x, y = [int(i) for i in input("->").split()]
    print(x, y)