DEV Community is a community of 787,570 amazing developers

We're a place where coders share, stay up-to-date and grow their careers. Abhishek.H

Posted on • Updated on

How To Make A Simple Calculator in Python

If you're new to Python, here is a simple project for you! Create an extremely simple Calculator to improve your skills! In this article, I will show you how to make one.

Making The Inputs

Here, we need to create three inputs for the user to input their desired values.

First we create num1, i.e the first number the user needs to calculate.

num1 = int(input("❯ Enter The First Number: "))

Second, we create operator so that the user can input the operator. For example, if the user need to multiply, they can simply enter *.

operator = (input("❯ Enter '+', '-', '*' or '/' "))

Lastly for the inputs, we create num2, i.e the second number the user needs to calculate.

num2 = int(input("❯ Enter The Second Number: "))

Do not forget to add int(integer) before the inputs!

Writing Logic

Now we are going to code the logic behind that calculator.

If Statements

Using if statements, we are going to code so that the calculator respectively adds, subtracts, multiplies or divides.

if operator == '+':

Subtraction

if operator == '-':

Multiplication

if operator == '*':

Division

if operator == '/':

That's it for the logic!

The Final Step

That last thing you need to do is print it! 