![Calculator Program In Python 1 Calculator Program In Python](https://i0.wp.com/copyassignment.com/wp-content/uploads/2022/06/Calculator-Program-In-Python.jpg?fit=675%2C506&ssl=1)
We are presenting you with one of the shortest and simplest calculator programs in python you could ever found. This calculator will contain the most basic functions you have seen in your life.
We will be creating a calculator that will add, subtract, divide, and multiply two numbers.
We will run the program until we don’t want to exit using a while loop, so that we can calculate as many as calculations we want.
If you want the calculator program in python gui then click here.
First, we will ask the user to choose one of the four basic operations i.e. “Addition“, “Subtraction“, “Multiplication“, and “Division“.
print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division")
We will also give choice to the user so that he can exit the program whenever he wants.
print("5. Exit")
Now, we will store the value entered by the user using the variable “choice“.
choice = int(input("Enter your choice: "))
Now, we will see the code and we will use comments to explain to you this basic Calculator Program In Python.
Calculator Program In Python: Code
# creating while loop while True: # printing the available options print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") print("5. Exit") # asking user to Enter his choice choice = int(input("Enter your choice: ")) # checking the choice between 1 and 4 if (choice>=1 and choice<=4): # asking to enter two options print("Enter two numbers: ") # accepting first number num1 = int(input()) # accepting second number num2 = int(input()) # checking if number is 1 if choice == 1: # adding res = num1 + num2 # printing Addition print("Result = ", res) # checking if number is 2 elif choice == 2: # Subtracting res = num1 - num2 # printing Subtraction print("Result = ", res) # checking if number is 3 elif choice == 3: # Multiplication res = num1 * num2 # printing Result print("Result = ", res) # after checking all 3 choice, # only one operation left, i.e. for Division else: # Division res = num1 / num2 # printing Result print("Result = ", res) # checking if the choice is 5 elif choice == 5: # if choice is 5, we will exit the program exit() # everything, except the five choices is useless # so, we will print Wrong input..!! else: print("Wrong input..!!")
Calculator Program In Python: Output
1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter your choice: 1 Enter two numbers: 12 23 Result = 35 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter your choice: 2 Enter two numbers: 23 12 Result = 11 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter your choice: 3 Enter two numbers: 12 23 Result = 276 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter your choice: 4 Enter two numbers: 24 12 Result = 2.0 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter your choice: 5
This progam is very basic level Calculator Program In Python for beginners. But, we can add more choice and operations according to our needs.
Thanks for reading
Keep Learning
If you found something wrong in the article, then please let us know.
Also Read:
- ChatGPT vs DeepSeek: Who is the winner?Here’s a detailed comparison between ChatGPT (specifically GPT-4o) and DeepSeek-V3 based on various online resources, focusing on key metrics such as time to build, cost, performance, and other relevant factors: 1. Architecture and Model Size 2. Training Cost and Efficiency 3. Performance Benchmarks 4. Cost of Usage 5. Open-Source and Accessibility 6. Real-World Applications 7….
- People are becoming AI Engineer with this free course in 2025: Here is how to join this…Artificial Intelligence (AI) has become a cornerstone of technological advancement, shaping industries and transforming careers. If you’ve been looking to upskill or dive into the fascinating world of AI, freeCodeCamp.org has released an incredible resource: the AI Foundations Course on YouTube. This 11-hour video, created by @LunarTech_ai, is not just another crash course – it’s…
- Apply to Google’s Student Training in Engineering Program (STEP) Intern, 2025Google’s Student Training in Engineering Program (STEP) Intern, 2025, is a fantastic opportunity for students passionate about programming and software development. Designed to support skill-building and career growth, this program offers a chance to work with one of the world’s leading tech companies. Here’s everything you need to know about this internship opportunity. What Is…
- Self-Driving Car Saves Falling Pedestrian, Showcases Promise of Autonomous TechnologyIn a dramatic demonstration of the potential for self-driving technology to enhance road safety, a Waymo’s autonomous vehicle recently avoided a serious accident when a scooter rider, startled by a pothole, lost balance and fell onto the road. The incident, captured on video, highlights the advanced capabilities of modern driverless technology. As the rider tumbled…
- Instant Karma: Employer Fires Tech Team with AI, Faces Backlash on LinkedIn While Seeking New DevelopersIn a bold—and controversial—move, Canadian software developer Wes Winder has sparked heated online debates after replacing his entire development team with Artificial Intelligence (AI). Winder, who took to LinkedIn to announce his decision, has been met with a wave of criticism and ridicule, with many questioning the practicality and ethics of his approach. The Controversial…