Computer Science, asked by woodylite, 11 months ago

can you code in the program python to add two numbers​

Answers

Answered by Equestriadash
7

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

\tt Enter\ first\ number: 5

\tt Enter\ second\ number: 6

\tt Their\ sum\ is\ 11

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:

\tt Enter\ first\ number: 8

\tt Enter\ second\ number: 9

\tt Their\ sum\ is\ 89

This is why, if ever we need to perform calculations, the int() function must be used.

Answered by atrs7391
0

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

sum = a + b

print("Sum of the numbers =", sum)

Similar questions