Python Calculator Simple Program With Examples

Python Calculator

In this quick post, we will see how we can create a very simple python calculator program. We will take input from the user about the operation he wants to perform and show the result on its basis. Let’s get started with our python calculator code right away.

Modular Code

To keep things modular, we will define functions to perform various operations. Here are the operations our calculator will support for numbers:

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Raising a power to number


Let’s do our first operation of Addition here:

We used a simple function so that our code remains modular.


Second operation involves subtracting two numbers:


Third operation involves multiplying two numbers:


Fourth operation involves dividing two numbers:

Raising a power to number

Our final operation involves raising a number by a power. Note that to do this, we can use mathematical operator **:

Taking user input

Time to present the user with available choices and taking an input from him:

Deciding operation

Finally, we can decide which function to call when user has provided an input:

When we run this program, we will be able to perform mathematical operations:



In this quick post, we defined a very simple Python calculator and kept the code modular as well so that we can reuse the functions accordingly.

By admin

Leave a Reply