Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab67ad2

Browse files
Update app.py
1 parent 3ce2d05 commit ab67ad2

File tree

1 file changed

+62
-5
lines changed
  • Medium-Questions/72-level-2-equations/Python

1 file changed

+62
-5
lines changed

‎Medium-Questions/72-level-2-equations/Python/app.py‎

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,74 @@
11
import os
22
import sys
3+
import math
34

5+
class EquationTwo:
46

5-
def solve(a:int, b:int, c:int) -> float:
6-
...
77

88

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+
1168

1269

1370
def main():
14-
pass
71+
EquationTwo(a=0, b=0, c=0)
1572

1673

1774
if __name__ == "__main__":

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /