-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3 Cases added
20 lines (17 loc) · 908 Bytes
/
3 Cases added
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Python Program to find roots of a Quadratic Equation
import math
a = int(input("Please Enter a Value of a Quadratic Equation : "))
b = int(input("Please Enter b Value of a Quadratic Equation : "))
c = int(input("Please Enter c Value of a Quadratic Equation : "))
discriminant = (b * b) - (4 * a * c)
if(discriminant > 0):
root1 = (-b + math.sqrt(discriminant) / (2 * a))
root2 = (-b - math.sqrt(discriminant) / (2 * a))
print("Two Distinct Real Roots Exists: root1 = %.2f and root2 = %.2f" %(root1, root2))
elif(discriminant == 0):
root1 = root2 = -b / (2 * a)
print("Two Equal and Real Roots Exists: root1 = %.2f and root2 = %.2f" %(root1, root2))
elif(discriminant < 0):
root1 = root2 = -b / (2 * a)
imaginary = math.sqrt(-discriminant) / (2 * a)
print("Two Distinct Complex Roots Exists: root1 = %.2f+%.2f and root2 = %.2f-%.2f" %(root1, imaginary, root2, imaginary))