#!/usr/bin/python
import sys
class Cacl:
def __init__(self, x, y, op):
self.x = x
self.y = y
self.op = op
# Calculation method
def add(self):
return self.x + self.y
def sub(self):
return self.x - self.y
def mul(self):
return self.x * self.y
def div(self):
return self.x / self.y
# Deal ERROR
def op_error(self):
print 'Calculation types are not supported: ', self.op
sys.exit()
# External interface
def compute(self):
try:
return {
'+' : self.add(),
'-' : self.sub(),
'*' : self.mul(),
'/' : self.div()
}[self.op]
except:
self.op_error()
def main():
# get input str
# debug: # in_str = '1 - 2'
in_str = str(raw_input("input like a + b then Enter: "))
try:
x = float(in_str.split(' ')[0])
op = in_str.split(' ')[1]
y = float(in_str.split(' ')[2])
except:
print 'input error'
sys.exit()
print in_str + ' = ' + str(Cacl(x, y, op).compute())
if __name__ == '__main__':
main()