can you code in the program python to add two numbers
Answers
Code to add two numbers.
The following codes must be written in script mode, saved and then executed.
CODE
x = int(input("Enter first number:"))
y = int(input("Enter second number:"))
print("Their sum is", x+y)
OUTPUT
5
6
We've used two functions, int() and input().
int() is to convert the value entered into an integer type whilst input() is to convert the value entered into a string type. If we were to write the above codes without int(), this is how the output would be.
CODE:
x = input("Enter first number:")
y = input("Second number:")
print("Their sum is", x+y)
OUTPUT:
8
9
This is why, if ever we need to perform calculations, the int() function must be used.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
sum = a + b
print("Sum of the numbers =", sum)