How To Make Basic Calculator Using Python Programming Langauge

In this lesson, you will learn about how to make basic calculator using Python Programming Language and believe me its very simple and fun. This calculator just performs basic arithmetic functions like addition, subtraction, multiplication, and division.  This simple calculator takes the input from the user and then performs the desired operation on the given input. All this is done in the following steps.

• A user gives the input 2 times with their desire number like 1, 2, 3, and so forth.
• Then if input evaluated/tested with if,…else statements to test the user given input and to decide what to do with this input.
• Then we use functions for all the four operations mentioned earlier.
Recommended:  Advantages & Applications Of Python Programming Language

See the below example:

#Below code shows the steps for performing operations
# A form of basic calculator
Please select what you want to do
2. Subtraction
3. Multiplication
4. Division
Please Select from above operations numbers 1, 2, 3, 4: 1
Please enter the second number: 23
10 + 23 = 33

See the example code below:

# A simple program for making basic calculator
# This function use for addition
return num1 + num2
# This function use for subtraction
def subtract(num1, num2):
return num1 - num2
# This function use for multiplication
def multiply(num1, num2):
return num1 * num2
# This function use for division
def divide(num1, num2):
return num1 / num2
print("Please select what you want to do  -n"
"2. Subtractionn"
"3. Multiplicationn"
"4. Divisionn")
# This step takes the input from the user
select = input("Please choose your desired operation form 1, 2, 3, 4 :")
number_1 = int(input("Please enter your first number: "))
number_2 = int(input("Please enter your first number: "))
if select == '1':
print(number_1, "+", number_2, "=",
elif select == '2':
print(number_1, "-", number_2, "=",
subtract(number_1, number_2))
elif select == '3':
print(number_1, "*", number_2, "=",
multiply(number_1, number_2))
elif select == '4':
print(number_1, "/", number_2, "=",
divide(number_1, number_2))
else:
print("It is an Invalid input")

Code Output:

#This is the output of code
Please select what you want to do -