## DEV Community is a community of 862,249 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Posted on

# A simple python calculator

i made a simple python calculator using while loop

``````# simple calculator

return x + y

def sub(x, y):
return x - y

def mul(x, y):
return x * y

def div(x, y):
return x / y

print("Select operation.")
print("( - ) for Subtract")
print("( * ) for Multiply")
print("( / ) for Divide")

while True:
choice = raw_input("Enter the operation: ")
if choice in ('+', '-', '/', '*'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == '+':
print num1, "+", num2, "=", (add(num1, num2))
elif choice == '-':
print num1, "-", num2, "=", (sub(num1, num2))
elif choice == "*":
print num1, "*", num2, "=", (mul(num1, num2))
elif choice == '/':
print num1, "/", num2, "=", (div(num1, num2))
n12 = raw_input("Do u want to calculate another equation (y/n): ")
if n12 == 'y' or n12 == 'Y':
continue
else:
break

``````