|
1 | 1 | import os |
2 | 2 | import sys |
| 3 | +import math |
3 | 4 |
|
| 5 | +class EquationTwo: |
4 | 6 |
|
5 | | -def solve(a:int, b:int, c:int) -> float: |
6 | | - ... |
7 | 7 |
|
8 | 8 |
|
9 | | -def check_ans(a:int, b:int, c:int) -> float: |
10 | | - ... |
| 9 | + def __init__(self, a, b, c): |
| 10 | + self.a = a |
| 11 | + self.b = b |
| 12 | + self.c = c |
| 13 | + |
| 14 | + |
| 15 | + def calculate_delta(self) -> float: |
| 16 | + # delta = b**2-4ac |
| 17 | + self.delta = float((self._b**2)-4*(self._a)*(self._c)) |
| 18 | + return self.delta |
| 19 | + |
| 20 | + def check_delta(self) -> int: |
| 21 | + """ this method return number of answers """ |
| 22 | + if self.delta == 0: |
| 23 | + return 1 |
| 24 | + elif self.delta > 0: |
| 25 | + return 2 |
| 26 | + else: |
| 27 | + return 0 |
| 28 | + |
| 29 | + def calculate_answer(self): |
| 30 | + # -b - sqrt(delta) / 2a |
| 31 | + # -b + sqrt(delta) / 2a |
| 32 | + |
| 33 | + return [ ((-(self._b) - math.sqrt(self.delta))/2*self._a), (-(self._b) + math.sqrt(self.delta))/2*self._a ] |
| 34 | + |
| 35 | + @property |
| 36 | + def a(self): |
| 37 | + return a |
| 38 | + |
| 39 | + @a.setter |
| 40 | + def set_a(self, value): |
| 41 | + if not(value != 0): |
| 42 | + print("IMPOSSIBLE") |
| 43 | + sys.exit(1) |
| 44 | + self._a = value |
| 45 | + |
| 46 | + @property |
| 47 | + def b(self): |
| 48 | + return b |
| 49 | + |
| 50 | + |
| 51 | + @b.setter |
| 52 | + def set_b(self, value): |
| 53 | + if not(value != 0): |
| 54 | + print("IMPOSSIBLE") |
| 55 | + sys.exit(1) |
| 56 | + self._b = value |
| 57 | + |
| 58 | + |
| 59 | + @property |
| 60 | + def c(self): |
| 61 | + return c |
| 62 | + |
| 63 | + @a.setter |
| 64 | + def set_a_value(self, value): |
| 65 | + if not (a != 0): |
| 66 | + raise ValueError("IMPOSIBLE a cannot be 0") |
| 67 | + |
11 | 68 |
|
12 | 69 |
|
13 | 70 | def main(): |
14 | | - pass |
| 71 | + EquationTwo(a=0, b=0, c=0) |
15 | 72 |
|
16 | 73 |
|
17 | 74 | if __name__ == "__main__": |
|
0 commit comments