Share your repls and programming experiences

← Back to all posts
Simple Calculator
phitsee (5)

Simple text-based calculator // does 4 main operator functions

Commentshotnewtop
bhuvenbhuven862 (1)

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

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

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

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

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

def remainder(x, y):
return x % y

x = float(input("Enter a number: "))
y = float(input("Enter another number: "))

choice = (
"1. Add",
"2. Subtract",
"3. Multiply",
"4. Divide",
"5. Quotient",
"6. Remainder",
)
print(choice)
select = input("Pick a number: [1/2/3/4/5/6] \n")

if select == '1':
print(x, "+", y, "=", add(x, y))

elif select == '2':
print(x, "-", y, "=", subtract(x, y))

elif select == '3':
print(x, "*", y, "=", multiply(x, y))

elif select == '4':
print(x, "/", y, "=", divide(x, y))
elif select == '5':
print(x, "//", y, "=", quotient(x, y))
elif select == '6':
print(x, "%", y, "=", remainder(x, y))
else:
print("Invalid input")
I added two more functions

TaylorLiang (647)

@bhuvenbhuven862
1. Put your thing in a code block
2. Indent using 2 or 4 spaces
3. Use lambda functions for basic math