Want to know how to add two numbers in python then today I will show you how to create a python program to add two numbers. It is one of the most basic program in python which every beginner should try to create.
After reading this python program tutorial you can further create a python calculator program which can calculate numeric values if you want to know how to create a calculator in python then you can read this guide – Making a calculator in python.
Python addition program is very simple and easy I will show you step by step how to add two numbers in python so follow up with me till the end.
First let’s see how this addition python program will work:
- We will create 2 variables num1 and num2 which will take inputs from the user
- Then we will create another variable result which will be the sume of variable num1 and num2
- We will use the + operator in python to add num1 and num2
- Lastly we will print the result which will be the the sum of variable num1 and num2
This was a quick explaination how this python program will work now let’s see how this will look in python code.
# Store input numbers num1 = input('Enter the first number: ') num2 = input('Enter the second number: ') # Add two numbers result = float(num1) + float(num2) # Display the result print(result)
As you can see above that is the python program to add 2 numbers it will ask the user for the first time to enter the first number after entering that it will ask to enter the second number then it will add both numbers using the + operator in python.
Then the total sum of both values will be equalled to result then we print the result you can test this program and see the output below is the example output of this program.
Enter the first number: 3 Enter the second number: 4 7
So this was a simple python program for adding two numbers you can expand upon this program and create a full calculator program.
I hope you found what you were looking for and if you want more tutorial like this you can check our Python projects and if you want to get updated on our latest guides you can join us on Telegram – Join Coderzway Telegram channel.
Thank you for reading, Have a nice day 🙂