How To Make A Simple Python 3 Calculator Using Functions

Himanshu Tyagi
Last updated on Apr 19, 2020

Our guides are based on hands-on testing and verified sources. Each article is reviewed for accuracy and updated regularly to ensure current, reliable information.Read our editorial policy.

Here, you will learn how to make a simple Python 3 calculator. To understand this example, you should know basic Python programming concepts such as variables, operators, functions, and if-else statements.

Also ReadSending Emails Using Python With Image And PDF Attachments.

Steps To Make A Simple Calculator Using Python 3

Step 1: First, we will take two numbers input from the user using the input function.

Step 2: After that, we will create functions to perform arithmetic operations such as division, multiplication, subtraction, and addition. These functions will take two inputs (two numbers) and return the result of that operation.

To perform these operations, we will define four functions – multiplication(num1, num2), addition(num1, num2), subtraction(num1, num2), and divide(num1, num2).

Step 3: Next, we will provide the option to choose an operation (division, multiplication, subtraction, and addition). We can implement it by asking users to enter a digit to select the arithmetic operation they want to perform on the input numbers.

Users will see the following message on their console application – “Select operation 1-Division, 2-Multiplication, 3-Addition, 4-Subtraction.”

Step 4: Now, users can choose the operation they want to perform. Suppose the user selects the first operation; then they must enter 1, and then our program will display the operation result.

Python 3 code for a simple calculator

code
#Python Program to Make a Simple Calculator

def multiplication(num1, num2):
    return num1 * num2

def addition(num1, num2):
    return num1 + num2

def subtraction(num1, num2):
    return num1 - num2

def divide(num1, num2):
    return num1 / num2

value1 = int(input("Enter 1st number: "))
value2 = int(input("Enter 2nd number: "))

print("Select operation 1-Division, 2-Multiplication, 3-Addition, 4-Subtraction")
operation = int(input("Choose operation 1/2/3/4: "))

if operation == 1:
    print(value1, "/", value2, "=", divide(value1, value2))

elif operation == 2:
   print(value1, "*", value2, "=", multiplication(value1, value2))

elif operation == 3:
   print(value1, "+", value2, "=", addition(value1, value2))
elif operation == 4:
   print(value1, "-", value2, "=", subtraction(value1, value2))
else:
   print("Enter correct operation")

Output:

Enter 1st Number: 2
Enter 2nd Number: 2
Select operation 1-Division, 2-Multiplication, 3-Addition, 4-Subtraction
Choose operation 1/2/3/4: 1
2 / 2 = 1.0

output python calculator

Try it yourself:

Summing Up

With this tutorial, you can create a basic Python 3 calculator. However, feel free to play with the code by adding more functionalities.

Stay tuned, and we will also share the tutorial to build a GUI calculator application using Python.

If you have any queries, please let me know in the comments section, and I will try my best to assist you.

Himanshu Tyagi

About Himanshu Tyagi

At CodeItBro, I help professionals, marketers, and aspiring technologists bridge the gap between curiosity and confidence in coding and automation. With a dedication to clarity and impact, my work focuses on turning beginner hesitation into actionable results. From clear tutorials on Python and AI tools to practical insights for working with modern stacks, I publish genuine learning experiences that empower you to deploy real solutions—without getting lost in jargon. Join me as we build a smarter tech-muscle together.

Free Online Tools

Try These Related Tools

Free browser-based tools that complement what you just read — no sign-up required.

Keep Reading

Related Posts

Explore practical guides and fresh insights that complement this article.

Web Scraping in Python: A Practical Guide for Developers
Programming

Web Scraping in Python: A Practical Guide for Developers

Use Python web scraping to collect publicly available web data and convert it into clean JSON, CSV, or database records. Start with requests and BeautifulSoup for normal HTML pages. Use Playwright only when the page needs JavaScript to load the data. Here is the smallest useful version. For example: import requests from bs4 import BeautifulSoup […]

Python Glossary: 150+ Key Terms and Definitions Explained
Programming

Python Glossary: 150+ Key Terms and Definitions Explained

Welcome to the Python Glossary — This guide explains common Python terms in clear, simple language. It helps beginners learn the basics and gives experienced developers a quick way to refresh their knowledge. You’ll find short, direct definitions covering Python’s core features, built-in tools, and useful programming ideas. A ABI (Application Binary Interface): The binary interface […]

A Hands-On Guide to Supervised Machine Learning in Python
Programming

A Hands-On Guide to Supervised Machine Learning in Python

Have you ever wondered how Netflix recommends movies and shows that you might like more accurately? Well, that is supervised machine learning at work. Businesses are using machine learning to solve complex predictive and classification problems, from predicting diseases to enabling self-driving cars. Python has become a versatile tool for building and training supervised machine […]