File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import math
2+ print ("General form of quadratic is: ax^2 + bx + c, where (a!=0)." )
3+ a = int (input ("Enter the value for a: " ))
4+ if a == 0 :
5+ print ("a can't be equals to zero." )
6+ else :
7+ b = int (input ("Enter the value for b: " ))
8+ c = int (input ("Enter the value for c: " ))
9+ if c == 0 :
10+ print (f"The quadratic is: { a } x^2 + { b } x" )
11+ else :
12+ print (f"The quadratic is: { a } x^2 + { b } x + { c } " )
13+
14+ d = b ** 2 - 4 * a * c
15+
16+ if d < 0 :
17+ d = d * (- 1 )
18+ x = str (2 * a )
19+ print ("This quadratic have complex roots." )
20+ root1 = (f"{ (- 1 * b )} + i{ round (math .sqrt (d ), 2 )} " )
21+ root2 = (f"{ (- 1 * b )} - i{ round (math .sqrt (d ), 2 )} " )
22+ print (f"The roots of given quadratic are \' { root1 } /{ x } \' and \' { root2 } /{ x } \' ." )
23+
24+ elif d == 0 :
25+ print ("This quadratic have equal roots." )
26+ print (f"Which is \' { (- b / (2 * a ))} \' ." )
27+
28+ else :
29+ print ("This quadratic have two real and distinct roots." )
30+ root1 = (- b + round (math .sqrt (d ), 2 ))/ (2 * a )
31+ root2 = (- b - round (math .sqrt (d ), 2 ))/ (2 * a )
32+ print (f"Which are \' { root1 } \' and \' { root2 } \' ." )
You can’t perform that action at this time.
0 commit comments