Addition Program in Python
In this tutorial, we are about build a very simple addition program in Python. We will show how to build a simple program that will add two integer numbers that a user gives us via the terminal or command prompt and then we will return the sum of those two numbers to the user. The program will be accessible to download at the end of the tutorial. Just try to follow along the more you practice writing programs in Python the more you will learn.
Building the Addition Python Program
We will be using sublime text as our text editor to build this program. We will be writing our code using Python 3 syntax. We will run the code via our terminal or command prompt.
Step 1 - Open Text Editor
Open your text editor so we can write the code for our program.
Step 2 - Save your program
Save your program to your desktop as addition.py
Step 3 - Write Welcome Message For Our Program
Here we will use a simple print statement to welcome our users to our program.
#Write Welcome Message For Our Program
print("Welcome to our addition program")
Step 4 - Get Users First Number
In this step, we will get the users first number using input() and then convert the number to an integer using int() and assign a variable to the object that holds the users first number.
#Get Users First Number
print("Welcome to our addition program")
firstnum = int(input("Give us your first number. "))
Step 5 – Get Users Second Number
In this step, we do the same for the previous step above but we give this user input a different variable.
#Get Users Second Number
print("Welcome to our addition program")
firstnum = int(input("Give us your first number. "))
secondnum = int(input("Give us your second number. "))
Step 6 – Perform The Equation
In this step, we will add the users two numbers together and then assign the sum a variable.
#Perform The Equation
print("Welcome to our addition program")
firstnum = int(input("Give us your first number. "))
secondnum = int(input("Give us your second number. "))
thesum = firstnum + secondnum
Step 7 – Return The Sum To The User
We will return the sum of the user. We will print a string to the user and format the string using a format() method to add our sum into the string.
#Return The Sum To The User
print("Welcome to our addition program")
firstnum = int(input("Give us your first number. "))
secondnum = int(input("Give us your second number. "))
thesum = firstnum + secondnum
print("Your sum is ".format(thesum))
Step 8 – Run The Program
Open your terminal or command prompt and change into your desktop. To run the program, simply type python3 addition.py and press return or enter. The program will ask you to input a number then press return. The program will again prompt you to add your second number again input your number then press return. Now the program will return your sum to you. This is a very simple program in Python.
If you have any questions about Addition Program in Python please leave a comment below and we will help you out.
Addition Program in Python
Thanks for sharing this tutorial. It is really helpful.
ReplyDeletePython Training course | Python Training Chennai | Python courses in Chennai
I believe that your blog will surely help the readers who are really in need of this vital piece of information.
ReplyDeleteFrench Coaching near me
French Course in Chennai
French Training Institutes in Chennai
Spanish Language Course in Chennai
Spanish Courses in Chennai
Japanese Language Course in Chennai
Japanese Coaching Center near me
Hiii....Thanks for sharing Great information...Nice post....Keep move on....
ReplyDeletePython Training in Hyderabad
advantages of lifi,benefits of lifi, working of lifi,
ReplyDeletelifi technology, lifi in hindi,lifi in urdu, lifi internet,
light fidelity,lifi speed,
LiFi Technology ?
What Is LiFi ? How Does Lifi Work?
Really i found this article more informative, thanks for sharing this article! Also Check here
ReplyDeleteDownload and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows
Vidmate App Download
Vidmate apk for Android devices
Vidmate App
download Vidmate for Windows PC
download Vidmate for Windows PC Free
Vidmate Download for Windows 10
Download Vidmate for iOS
Download Vidmate for Blackberry
Vidmate For IOS and Blackberry OS
Tally Course | Tally Institute
ReplyDeleteExcellent blog with lots of information. I have to thank for this. Do share more.
This is extremely enlightening and intriguing article.Nice to peruse your blog entry first time ever. I truly welcome this post. A debt of gratitude is in order for sharing this great post.
ReplyDeleteCyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course |
CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course
meghan-duchess-of-sussex
ReplyDeleteTrade Capital Options: Trade245 Offers Customers The Opportunity To Trade A Wide Array Of Assets And Financial Instruments With A 30p Per Lot Commission.
ReplyDeleteIf You Are Looking For Forex Broker? Read This Review And Find Out How Much I've Enjoyed My Experience With ETRADE LOG ON
ReplyDeleteRead In Depth Fxtm Review Login
ReplyDelete