# How to Create a Calculator Using Python 2.7.x Python Secret #Author: ManishHacker1

Hello guys, I am back. Today we will create a simple Calculator using Python 2.7.x version. This calculator perform basic mathematical operation such as add, minus, multiply and divide two number entered by user.

## Source Code

```
#ManishHacker1
from __future__ import division
import os
import time

# 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
while True:
print("Select operation.")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

# Take input from the user
try:
choice = int(raw_input("Enter choice(1/2/3/4):"))
except:
print "Invalid Value, Please Enter Right Option"
time.sleep(5)
os.system('cls')
else:
try:
num1 = int(raw_input("Enter first number: "))
num2 = int(raw_input("Enter second number: "))
except:
print "Invalid Value"
time.sleep(5)
os.system('cls')

else:
if choice == 1:
time.sleep(5)
os.system('cls')
elif choice == 2:
print num1,"-",num2,"=", subtract(num1,num2)
time.sleep(5)
os.system('cls')
elif choice == 3:
print num1,"*",num2,"=", multiply(num1,num2)
time.sleep(5)
os.system('cls')
elif choice == 4:
try:
print num1,"/",num2,"=", divide(num1,num2)
time.sleep(5)
os.system('cls')
except ArithmeticError:
print "Arithmetic Error, Please Enter Right Value"
time.sleep(3)
os.system('cls')
else:
print "Invalid input"
time.sleep(5)
os.system('cls')
```  Kryptora Digital Security Provided Python Training and Ethical Hacking Training

Source: Python Secret

Source: Python

## Like and Share

Summary Article Name
How to Create a Calculator Using Python 2.7.x
Description
This calculator perform basic mathematical operation such as add, minus, multiply and divide two number entered by user.
Author
Publisher Name
Kryptora
Publisher Logo 