Python Program to Add Two Numbers

« Previous Program Next Program »

Add Two Numbers in Python

To add two numbers in python, you have to ask from user to enter two numbers to find the sum of given two numbers as shown here in the program given below.

Python Programming Code to Add Two Numbers

Following python program ask from user to enter any two number to find and print the sum of those two numbers:

# Python Program - Add Two Numbers

print("Enter '0' for exit.");
print("Enter two numbers: ");
val1 = int(input());
val2 = int(input());
if val1 == 0:
    sum = val1 + val2;
    print("Sum of the given two number:",sum);

Here is the sample run of the above Python program shows how to add two numbers:

This is the initial output, asks from the user to enter any two number one by one:

add two numbers python

Now enter the first number say 10 and press enter, then enter the second number say 20 and press enter to watch the sum of given two number as shown here in the below screenshot:

add two number program python

Same program written and run directly on python shell.

python add two numbers

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test