Python Program to accept integer or float value from user and print

How to accept an integer or float value in python?

In the last python program, we mention how to accept a string using the function Input. We have already stated that the python programming language is simple and easy to use. Here we are going to accept an integer value or float value.

What you mean by an integer and float value?. An integer is a Whole number, which will be from zero to any value. And float is a value with Rational numbers. The float data type in python language is used to store a double precision real number. In this python program, we are accepting the value using the Input function, so we have to face an issue here.

In the python language, when we use the function Input it accepts only string values. So we have to convert the accepted string to integer or float before it is saved in the assigned variable. for that, we use the int and float function to do the same. After assigning the value to the memory, we have to use the print function to display the output in python.

ALGORITHM

STEP 1: Accept a string from the user and convert that to an integer using the int function.

STEP 2: Print the number which is saved in the variable num.

STEP 3: Accept another string from the user and convert that to float using the float function.

STEP 4: Print the float data using the print function in python programming.

Python Source Code

                                          num = int(input("Enter an Integer: "))
print(num)

num = float(input("Enter a float value: "))
print(num)
                                      

OUTPUT

Enter an Integer:  23
23

Enter a float value: 7.7
7.7