We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4e62829 commit 0aafaecCopy full SHA for 0aafaec
1 file changed
newcodes/answers/q53.py
@@ -0,0 +1,31 @@
1
+#!/usr/bin/env python
2
+# coding=utf-8
3
+
4
+import math
5
+import cmath
6
7
+def solve_be(a, b, c):
8
+ delta = b**2 - 4*a*c
9
+ if delta == 0:
10
+ #x = fractions.Fraction(-b, 2*a)
11
+ x = -b / (2*a)
12
+ return x
13
+ elif delta > 0:
14
+ sqrt_delata = math.sqrt(delta)
15
+ else:
16
+ sqrt_delata = cmath.sqrt(delta)
17
+ #x1 = fractions.Fraction((-b + sqrt_delata), 2*a)
18
+ #x2 = fractions.Fraction((-b - sqrt_delata), 2*a)
19
+ x1 = (-b + sqrt_delata) / (2*a)
20
+ x2 = (-b - sqrt_delata) / (2*a)
21
+ return (x1, x2)
22
23
+if __name__ == "__main__":
24
+ print("The binary linear equation is x^2 + 2^x + 3 = 0")
25
+ r = solve_be(1, 2, 3)
26
+ if len(r) == 1:
27
+ print("The equation only has one root. It is:")
28
+ print(r)
29
30
+ print("The equation have two root. They are:")
31
0 commit comments