Python Program to Make Calculator

« Previous Program Next Program »

Make Calculator in Python

To make simple calculator in python to perform basic mathematical operations such as add, subtract, multiply, and divide two numbers entered by the user. To make calculator in python, first provide 5 options to the user, the fifth option for exit. After providing all the five options to the user, ask from user to enter his/her choice and perform the desired operation as shown in the program given below.

Python Programming Code to Make Calculator

Following python program provides options to the user and ask to enter his/her choice to perform and show the desired result as output:

# Python Program - Make Simple Calculator

print("1. Addition");
print("2. Subtraction");
print("3. Multiplication");
print("4. Division");
print("5. Exit");
choice = int(input("Enter your choice: "));
if (choice>=1 and choice<=4):
    print("Enter two numbers: ");
    num1 = int(input());
    num2 = int(input());
    if choice == 1:
    	res = num1 + num2;
    	print("Result = ", res);
    elif choice == 2:
    	res = num1 - num2;
    	print("Result = ", res);
    elif choice == 3:
    	res = num1 * num2;
    	print("Result = ", res);
    	res = num1 / num2;
    	print("Result = ", res);
elif choice == 5:
    print("Wrong input..!!");

Here are some sample runs of the above python program to illustrates how to make a simple calculator.

This is the initial output giving users, some number of choices (5 choices) to choose any one from all these 5 choices.

python make calculator

Now let's first try for the addition task by choosing or typing 1 as input and then enter any two number say 1 and 2 and then press enter key to check it out:

python calculator

Now let's re-run the calculator program to this time check it out for subtraction of two numbers say 2 and 1 as shown in the following sample run:

calculator program python

Again re-run the same program, and this time, provide 4 as input to check for division task and supply two numbers, that is first number as 20 and second numbers as 3 then press enter key as shown here in the below sample run:

calculator code python

Here is the same program written and run on python shell. This is the first snapshot:

python make calculator

Below is the second snapshot:

python make simple calculator

Here is the third snapshot:

calculator program in python

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test