Build A Calculator Python Program Using OOP
Build A Calculator Python Program Using OOP
The user to choose what functionality they want to execute through an input,
then the user will input the required variables and the respective function will
be called to compute the result.
Sample Output:
class Calculator:
def add(self, a, b):
return a+b
while True:
print("1: Add")
print("2: Subtract")
print("3: Multiply")
print("4: Divide")
print("5: Exit")
#If not then ask fo the input and call appropiate methods
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if(ch == 1):
print(a, "+", b, "=", my_cl.add(a, b))
elif(ch == 2):
print(a, "-", b, "=", my_cl.subtract(a, b))
elif(ch == 3):
print(a, "*", b, "=", my_cl.multiply(a, b))
elif(ch == 4):
print(a, "/", b, "=", my_cl.divide(a, b))
else:
print("Invalid Input")
PROGRAMMING QUIZ 2 FINALS: