# HOW TO MAKE A CALCULATOR IN PYTHON

In this article, we will learn how to create a simple calculator in Python.

In our calculator, basic operations like addition, subtraction, multiplication, and division. You need to have prior knowledge about functions to clearly understand this program. Once you get the idea, you can add many other features to the calculator.

#python program for simple calculator #addition function def add(n1, n2): return (n1 + n2) #subtraction function def sub(n1, n2): return (n1 - n2) #multiplication function def mul(n1, n2): return (n1 * n2) #division function def div(n1, n2): return (n1 / n2) print("****SIMPLE CALCULATOR****") print("1. Add\n2. Subtract\n3. Multiply\n4. Divide\n") #take input from user choice = int(input("Select operations form 1, 2, 3, 4 : ")) num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) if choice==1: print(add(num1, num2)) elif choice==2: print(sub(num1, num2)) elif choice==3: print(mul(num1, num2)) elif choice==4: print(div(num1, num2)) else: print("Invalid input")

****SIMPLE CALCULATOR**** 1. Add 2. Subtract 3. Multiply 4. Divide Select operations form 1, 2, 3, 4 : 3 Enter first number: 3 Enter second number: 7 21

Subscribe

Login

Please login to comment

0 Discussion