# Python Calculator Simple Program With Examples [Latest]

Sep 13, 2021

## 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:

• 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.

### Subtraction

Second operation involves subtracting two numbers:

### Multiplication

Third operation involves multiplying two numbers:

### Division

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:

## Conclusion

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.