 # Python Program to Make Basic Calculator

Simple calculator program in python; In this tutorial, you will learn how to create a basic calculator that can add, subtract, multiply or divide depending upon the input from the user.

To understand this python program, you should have knowledge of python functions.

To create a basic method in python program, which is used to perform arithmetic operations.

Let’s do our first operation of Addition here:

```def add(x, y):
return x + y;

```

We used a simple function so that our code remains modular.

### 2. Subtraction

Second operation involves subtracting two numbers:

```def subtract(x, y):
return x - y;

```

### 3. Multiplication

Third operation involves multiplying two numbers:

```def multiply(x, y):
return x * y;

```

### 4. Division

Fourth operation involves dividing two numbers:

```def devide(x, y):
return x / y;
```

## Calculator Program in Python using Functions

```# Program create a simple calculator

# This function adds two numbers
return x + y

# This function subtracts two numbers
def subtract(x, y):
return x - y

# This function multiplies two numbers
def multiply(x, y):
return x * y

# This function divides two numbers
def divide(x, y):
return x / y

print("Select operation.")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

# Take input from the user
choice = input("Enter choice(1/2/3/4): ")

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == '1':

elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
```

Output

```Select operation.
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4):  1
Enter first number:  10
Enter second number:  15
10.0 + 15.0 = 25.0```

## Recommended Python Programs 