0

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

0

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

you can also use this solution for more variables like x, y, z, u = [the same code]
0

You are taking int as input which cant be split

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

you can change to int if you like later

print(int(x),int(y))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.