Calculator
We will create a basic addition calculator.
Code explanation
- Save numbers into
num1
andnum2
. - We will change to a float number
float()
. - We will add
num1
andnum2
.
Since int()
only works for integers, we will use float()
to convert the result to a float number.
Note that adding to integers with float()
will result in numbers with .0
at the end.
Making the calculator
Input the numbers into the input fields.
num1 = input("Number 1: ")
num2 = input("Number 2: ")
float()
converts the input to a float number.
addnum = float(num1) + float(num2)
Print the added number.
print(addnum)