Skip to content

Simple Calculator

These codes add/substract/mutiply/divide two numbers:

#create a function for adding
def add(x,y):
    return x+y
#create a function for subtracting
def subtract(x,y):
    return x-y
#create a function for multiplying
def multiply(x,y):
    return x*y
#create a function for dividing
def divide(x,y):
    return x+y

print("Select your choice:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
#get operation
operation=input("Enter your choice 1/2/3/4:")

#get numbers
x=int(input("Enter first number:"))
y=int(input("Enter second number:"))

#logical process
if (operation=="1"):
elif (operation=="2"):
elif (operation=="3"):
elif (operation=="4"):
Published inPython

Be First to Comment

Leave a Reply

%d bloggers like this: