-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.py
67 lines (42 loc) · 1.74 KB
/
Calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from abc import ABCMeta, abstractmethod
from scipy.misc import derivative as deriv
from Validator import NumberValidator as valid
class DivException(Exception):
pass
class AbstractCalculator:
__metaclass__ = ABCMeta
def Add(firstInput, secondInput):
pass
def Subtract(firstInput, secondInput):
pass
def Divide(firstInput, secondInput):
pass
def Multiply(firstInput, secondInput):
pass
def Derivative(function, x0, dx, n):
pass
class Calculator:
def __init__(self):
pass
def Add(self, firstInput, secondInput):
firstNumber = valid(firstInput)
secondNumber = valid(secondInput)
if (firstNumber.validateIfNumber() and secondNumber.validateIfNumber()):
return firstInput + secondInput
def Subtract(self, firstInput, secondInput):
firstNumber = valid(firstInput)
secondNumber = valid(secondInput)
if (firstNumber.validateIfNumber() and secondNumber.validateIfNumber()):
return firstInput - secondInput
def Multiply(self, firstInput, secondInput):
firstNumber = valid(firstInput)
secondNumber = valid(secondInput)
if (firstNumber.validateIfNumber() and secondNumber.validateIfNumber()):
return firstInput * secondInput
def Divide(self, firstInput, secondInput):
firstNumber = valid(firstInput)
secondNumber = valid(secondInput)
if (firstNumber.validateIfNumber() and secondNumber.validateIfNumber() and secondNumber.validateIfNotZero()):
return firstInput / secondInput
def Derivative(self, function, x0, dx, n):
return deriv(function, x0, 1.0, n)