Simple Calculator

I LOVE DOING THIS :)

#!/opt/python3

class Calculator:
	def __init__(self, inputa, inputb):
		self.a = inputa
		self.b = inputb

	def add(self):
		return (self.a + self.b)

	def mul(self):
		return (self.a * self.b)

	def sub(self):
		return (self.a - self.b)

	def div(self):
		if self.b == 0:
			try:
				print("Denominator cannot be zero, Please enter a non-zero number !")
				self.b = int(input())
				return (self.a / self.b)
			
			except ZeroDivisionError as e:
				print(e)
		else:
			return (self.a / self.b)


calc = Calculator(int(input()),int(input()))
print("The Addition of the two numbers are: %d" % calc.add())
print("The Multiplication of the two numbers are: %d" % calc.mul())
print("The Subtraction of the two numbers are: %d" % calc.sub())
print("The Division of the two numbers are: %g" % calc.div())

Last updated