﻿ Python: Input two integers in a single line - w3resource

# Python: Input two integers in a single line

## Python Basic: Exercise-134 with Solution

Write a Python program to input two integers on a single line.

Sample Solution-1:

Python Code:

``````# Print a message to instruct the user to input the values of 'x' and 'y'.
print("Input the value of x & y")

# Use 'map' to apply the 'int' function to the input values and split them into variables 'x' and 'y'.
x, y = map(int, input().split())

# Print the values of 'x' and 'y' after they have been assigned.
print("The value of x & y are: ", x, y)
```
```

Sample Output:

```Input the value of x & y
2 4
The value of x & y are:  2 4
```

Sample Solution-2:

Python Code:

``````# Prompt the user to input the values of 'a' and 'b' and split the input by spaces.
a, b = [int(a) for a in input("Input the value of a & b: ").split()]

# Print the values of 'a' and 'b' after they have been assigned.
print("The value of a & b are:", a, b)
```
```

Sample Output:

```Input the value of a & b:  2 4
The value of a & b are: 2 4
```

Python Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿