Input problem

why do I need to take input like this:
num1,num2 = map(int,input().split())
when i can just take input like that:
num1=int(input())
num2=int(input())
but this value error

The input is given in a single line spaced and hence, you gotta use map.

we use map to get input in single line and spaced rather than in different line

1 Like

Because the input provided is a single line spaced.

The map take values entered after space, in a single line. Whereas assigning it to other line, result in taking input in two lines.

map() takes two arguments. The first one is the method to apply, the second one is the data to apply it to. By this understanding, we can see this is doing nothing but typecasting every element of the list to an integer value.

difference will be there ,as in case 1 map takes two arg. as in your case it takes the input for two space separated variables and they have to be integer.
whereas, the second takes output in two different lines

the input is given in a single line whereas your program takes input in two lines. we use the map function to unpack the values and assign it to x and y.

We can use this method to unpack multiple values. learn about map first then try to solve the questions.