Python Input

In Python programming, the command line input (using keyboards) can be taken using either the input() method (Python 3) or the raw_input() method (Python 2). We will use the first method here for taking keyboard input.

 

Example 1

The following example shows the addition of two integer numbers using the input() method: 

# Input test for integer numbers
x = input("Enter value of a: ")
a = int(x)
y = input("Enter value of b: ")
b = int(y)
sum = a + b;
print("\nSUM:", sum)

Output:

Enter value of a: 10

Enter value of b: 20

SUM: 30
 

Example 2

The following example shows the addition of two floating-point numbers using the input() method: 

# Input test for floating-point numbers
x = input("Enter value of a: ")
a = float(x)
y = input("Enter value of b: ")
b = float(y)
sum = a + b;
print("\nSUM:", sum)

Output:

Enter value of a: 12.3

Enter value of b: 23.2

SUM: 35.5