- 123
A simple calculator in Python can perform basic arithmetic operations like addition, subtraction, multiplication, and division. Below is an example of a simple calculator program using functions.
# Function to add two numbersdef add(x, y):return x + y# Function to subtract two numbersdef subtract(x, y):return x - y# Function to multiply two numbersdef multiply(x, y):return x * y# Function to divide two numbersdef divide(x, y):return x / yprint("Select operation:")print("1. Add")print("2. Subtract")print("3. Multiply")print("4. Divide")while True:# Take input from the userchoice = input("Enter choice(1/2/3/4): ")# Check if choice is one of the four optionsif choice in ('1', '2', '3', '4'):try:num1 = float(input("Enter first number: "))num2 = float(input("Enter second number: "))except ValueError:print("Invalid input. Please enter a number.")continueif choice == '1':print(num1, "+", num2, "=", add(num1, num2))elif choice == '2':print(num1, "-", num2, "=", subtract(num1, num2))elif choice == '3':print(num1, "*", num2, "=", multiply(num1, num2))elif choice == '4':print(num1, "/", num2, "=", divide(num1, num2))# Check if user wants another calculationnext_calculation = input("Let's do next calculation? (yes/no): ")if next_calculation == "no":breakelse:print("Invalid Input") Python Program to Make a Simple Calculator
In this example you will learn to create a simple calculator that can add, subtract, multiply or divide depending upon the input from the user.
See results only from programiz.comFind LCM
Make a Simple Calculator. Python Tutorials. Python map() Function. Python …
Find The Factors of a Number
Learn to code solving problems and writing code with our hands-on Python course. …
Python Operators
In Python, in and not in are the membership operators. They are used to test whether …
Make a Simple Calculator – Python | GeeksforGeeks
Apr 12, 2025 · In this article, we will create a simple calculator that can perform basic arithmetic operations like addition, subtraction, multiplication and …
- Estimated Reading Time: 2 mins
Python Calculator Program
Learn how to write a basic calculator program in Python. This tutorial covers addition, subtraction, multiplication, and division with examples.
Simple Calculator Program in Python - W3Schools
Learn how to build a simple calculator in Python using basic mathematical calculations on user input. This step-by-step tutorial will walk you through the process of building a functional calculator that can add, subtract, multiply, and divide numbers.
Basic Calculator in Python - GitHub
A simple Python calculator that performs addition, subtraction, multiplication, and division. The user inputs the operation and two numbers, and the program displays the result.
Calculator Program in Python - AskPython
Dec 11, 2019 · In this article, We will be learning a simple command-line calculator program in Python 3. We’ll be using mathematical operators , Conditional statements, functions and handle user input to make our calculator.
- People also ask
- Some results have been removed