I'm a noob in programming (in python), I want to know how I could read data from user's keyboard in order to make a calculator for example based on the numbers he entered.
Thank you.
This is for sure a duplicate question but you can use this:
a = int(input("Enter the first number"))
b = int(input("Enter the second number"))
... do what you want with a
and b
.
The input()
statement is used for this purpose.
But the input statement accepts string input, so in order to take integral input, you need to convert the input to integers. Code:
a = int(input('Enter a Number'))
This will prompt the user to provide input and then store it in the variable a
. You can then use it anywhere. In the same way, if you want to input decimal numbers, you need to convert the type to float
:
a = float(input('Enter a Number'))