Home » Blog » Implement The Basic Calculator

Implement The Basic Calculator

Here we are using basic operator and function to implement basic calculator. This program provide basic use of operator and how to work with function.

con=1
while con==1:
	no1=int(input("Enter First Value "))
	no2=int(input("Enter Second Value "))
	print("Choice")
	print("1. Add")
	print("2. Subtract")
	print("3. Multiplication")
	print("4. Division")
	choice=int(input("Enter Choice "))

def Add():
	return (no1+no2)
def Sub():
	return (no1-no2)
def Mul():
	return (no1*no2)
def Div():
	return (no1/no2)

def perform_op(choice):
	if choice == 1:
		print(Add())
	elif choice == 2:
		print(Sub())
	elif choice == 3:
		print(Mul())
	elif choice == 4:
		print(Div())
	else:
		print("*** Invalid Choice ***")

perform_op(choice)

con=int(input("Do You Want To Continue "))

 

  • OutPut
Enter First Value 20
Enter Second Value 30
Choice
1. Add
2. Subtract
3. Multiplication
4. Division
Enter Choice 1
50
Do You Want To Continue 1
Enter First Value 23
Enter Second Value -3
Choice
1. Add
2. Subtract
3. Multiplication
4. Division
Enter Choice 2
26
Do You Want To Continue 1
Enter First Value 25
Enter Second Value 2
Choice
1. Add
2. Subtract
3. Multiplication
4. Division
Enter Choice 3
50
Do You Want To Continue 1
Enter First Value 32
Enter Second Value 4
Choice
1. Add
2. Subtract
3. Multiplication
4. Division
Enter Choice 4
8.0
Do You Want To Continue 1
Enter First Value 52
Enter Second Value 32
Choice
1. Add
2. Subtract
3. Multiplication
4. Division
Enter Choice 5
*** Invalid Choice ***
Do You Want To Continue 0

Leave a Reply

Your email address will not be published.