How Can I Read Inputs As A Numbers? In Python

In this Tutorial, we are going to discuss how How can I read inputs as numbers? in Python To read input from the console, we use the input inbuild function and get the input that the user wants to give to perform the actions which are required or we can say for which that program is designed.

Why Do We Need To Read Input As a Number?

We need to get input from the user to perform any actions. And to get that input and perform an action.

As we all know to perform any action or any task we need some input, sometimes it is fixed and in some places, it depends upon the situation, So if the input is already fixed then the output will also be fixed all the time we mean there was no benefit of designing a program as it is going to perform similar actions. So we have another way to feel with it which is taking input from the user and performing the action or calculations as per the user’s choice which makes the programming alive.

Taking Input

Now let’s take some examples to take input from users with the help of inbuilt function input().

x = input("Enter a number: ")
y = input("Enter a number: ")

   print(x + y)

The above program will take two inputs from the user and store them in x and y for using them in the future. As shown in the example program how we can take input as x and y and for printing output we can simply add(in this case) we can even perform any operations even sometimes we read String or decimal inputs and just them to indicate the variable use.

Now the answer or outcome of this program will not be fixed, It will depend upon h=whatexectly the input is given.
It will simply perform addition and return the sum of the two variables given.

We can learn more about reading inputs from: https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers

And we can also learn from Python Tutorial : Getting started with Python Programming

and perform the operations as per the given inputs

 

 

 

https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers

Leave a Comment

%d bloggers like this: