Example of basic Arithmetic Operation using Python

Rajnilari2015
Posted by Rajnilari2015 under Python category on | Points: 40 | Views : 127
class ParamArithmeticOperation(object):
def Main():
#calling function
ParamArithmeticOperation.PerformArithmeticOperation(200, 100, "+") #perform addition
ParamArithmeticOperation.PerformArithmeticOperation(200, 100, "-") #perform subtraction
ParamArithmeticOperation.PerformArithmeticOperation(200, 100, "*") #perform multiplication
ParamArithmeticOperation.PerformArithmeticOperation(200, 100, "/")

Main = staticmethod(Main)
#perform division
#called function
def PerformArithmeticOperation(items):
result = 0 #items[2] is the operator(s) i.e. +,-,*,/
if Convert.ToString(items[2]) == '+':
result = Convert.ToInt32(items[0]) + Convert.ToInt32(items[1])
elif Convert.ToString(items[2]) == '-':
result = Convert.ToInt32(items[0]) - Convert.ToInt32(items[1])
elif Convert.ToString(items[2]) == '*':
result = Convert.ToInt32(items[0]) * Convert.ToInt32(items[1])
elif Convert.ToString(items[2]) == '/':
result = Convert.ToInt32(items[0]) / Convert.ToInt32(items[1])
else:
Console.WriteLine("No such operation available")
Console.WriteLine(result)

PerformArithmeticOperation = staticmethod(PerformArithmeticOperation)

Comments or Responses

Login to post response