How to take float input in Python

In this tutorial, we will see how to take a float input in Python.

Actually, there is a difference between Python 2 and Python 3 regarding float() input.

In Python 2, we use float() input is rawx_input.

In Python 3, we use float() input is input.

In Python, It can’t identify the float() value directly as input. It will identify only when the float() Parameter is used otherwise it returns the float() as a string.

Let’s see with Examples.

Num = input("Enter a value:")
print(type(Num))

Output:

Enter a value: 2.34

<cls, ‘str’>

Num = float(input("Enter a value:"))
print("Entered value:", Num)
print("Type of Input:", type(Num))

Output:

Enter a value: 2.34

Entered value: 2.34

Type of Input: <cls, ‘float’>

Num1 = float(input("Enter a value:"))
Num2 = float(input("Enter a value:"))
print("Multiply of Two Inputs:", Num1 * Num2)

Output:

Enter a value: 20.50

Enter a value: 21.00

Multiply of  Two Inputs: 430.5

Also read: Float Precision in Python

Leave a Reply

Your email address will not be published. Required fields are marked *