We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 87bbc9a commit b35f0feCopy full SHA for b35f0fe
computeroots.py
@@ -0,0 +1,23 @@
1
+from math import sqrt
2
+
3
+print("Quadratic function : (a * x^2) + b*x + c")
4
+a = float(input("a: "))
5
+b = float(input("b: "))
6
+c = float(input("c: "))
7
8
+r = b**2 - 4*a*c
9
10
+if r > 0:
11
+ num_roots = 2
12
+ x1 = (((-b) + sqrt(r))/(2*a))
13
+ x2 = (((-b) - sqrt(r))/(2*a))
14
+ print("There are 2 roots: %f and %f" % (x1, x2))
15
+elif r == 0:
16
+ num_roots = 1
17
+ x = (-b) / 2*a
18
+ print("There is one root: ", x)
19
+else:
20
+ num_roots = 0
21
+ print("No roots, discriminant < 0.")
22
+ exit()
23
+- See more at: http://www.w3resource.com/python-exercises/math/python-math-exercise-30.php#sthash.gypCq4M0.dpuf
0 commit comments