MCPcopy Create free account
hub / github.com/geekcomputers/Python / DivisionOperation

Class DivisionOperation

Divide Operator.py:1–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class DivisionOperation:
2 INT_MAX = float("inf")
3
4 def __init__(self, num1, num2):
5 self.num1 = num1
6 self.num2 = num2
7
8 def perform_division(self):
9 if self.num1 == 0:
10 return 0
11 if self.num2 == 0:
12 return self.INT_MAX
13
14 neg_result = False
15
16 # Handling negative numbers
17 if self.num1 < 0:
18 self.num1 = -self.num1
19
20 if self.num2 < 0:
21 self.num2 = -self.num2
22 else:
23 neg_result = True
24 elif self.num2 < 0:
25 self.num2 = -self.num2
26 neg_result = True
27
28 quotient = 0
29
30 while self.num1 >= self.num2:
31 self.num1 -= self.num2
32 quotient += 1
33
34 if neg_result:
35 quotient = -quotient
36 return quotient
37
38
39# Driver program

Callers 1

Divide Operator.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected