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.
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: exit(); else: 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:
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:
Same program written and run directly on python shell.
You may also like to learn or practice the same program in other popular programming languages: