Calculations Class

This class provides basic calculation functions: add, subtract, division, multiplication, and mod

import sys

class calculations: 

	def printResult(self, funcName, thisResult): 

		self.funcName = funcName
		self.thisResult = thisResult

		print("\n")
		print('Entered ' + self.funcName)
		print('The Result is ' + str(self.thisResult)) 
		print('\n')

	def addThis(self, a,b):

		self.a = a
		self.b = b
		
		self.funcName = 'addThis'
		self.addResult = a + b
		self.printResult(self.funcName, self.addResult)
		
		return self.addResult

	def subThis(self,a,b): 

		self.a = a
		self.b = b

		self.funcName = 'subThis'
		self.subResult = b - a
		self.printResult(self.funcName, self.subResult) 

		return self.subThis

	def divThis(self, a,b): 

		self.a = a
		self.b = b

		self.funcName = 'divThis'
		self.divThis = int(a/b)
		self.printResult(self.funcName, self.divThis) 

		return self.divThis

	def multThis(self, a,b): 

		self.a = a
		self.b = b

		self.funcName = 'multThis'
		self.multThis = a*b
		self.printResult(self.funcName, self.multThis) 

		return self.multThis

	def modThis(self, a,b): 
		self.funcName = 'modThis'
		self.modThis = a % b
		self.printResult(self.funcName, self.modThis)  

		return self.modThis

About the Author

One thought on “Calculations Class

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these