-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_Quad_equation.py
54 lines (40 loc) · 1.12 KB
/
5_Quad_equation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Python program to solve quadratic equation
"""
#Method1.
import math as m
def unknown(a,b,c):
global x1,x2
if a and b and c >= 0 :
x1 = -b + m.sqrt((b**2 - 4*a*c)/2*a)
x2 = -b - m.sqrt((b**2 - 4*a*c)/2*a)
else :
print("Please enter values of a,b,c such as a,b,c == Real numbers and a!=0")
return x1,x2
def quadratic_equation(x1,x2,a,b,c) :
global equation1,equation2
equation1 = a*x1**2 + b*x1 + c
equation2 = a*x2**2 + b*x2 + c
return equation1,equation2
if __name__ == "__main__" :
a = int(input("a: "))
b = int(input("b: "))
c = int(input("c: "))
global x1,x2
global equation1,equation2
un = unknown(a,b,c)
quad = quadratic_equation(x1,x2,a,b,c)
print(f"Value of 'Unknown' x are:{x1} and {x2}")
print(f"Value of 'equation' are:{equation1} and {equation2}")
"""
#Method2
# import complex math module
import cmath
a = 1
b = 5
c = 6
# calculate the discriminant
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are {0} and {1}'.format(sol1,sol2))