-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEquation_Solver.py
54 lines (40 loc) · 1.02 KB
/
Equation_Solver.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
from math import *
def recup_a(x):
if x[0]=="-":
a= int(x[1])
s = -abs(a)
return s
if x[0]=="+":
a = int(x[1])
return a
a= int(x[0])
return a
def recup_b(x):
for i in range(3):
x = x[:-1]
return recup_c(x)
def recup_c(x):
if x[-2]=="+":
c = int(x[-1])
return c
if x[-2]=="-":
c = int(x[-1])
x=-abs(c)
return x
def CalcRacine(a,b,c):
delta = (b**2)-4*a*c
if delta >0:
racine1=(-(b)-sqrt(delta))/(2*a)
racine2=(-(b)+sqrt(delta))/(2*a)
return racine1, racine2, "sont solution de l'equation"
if delta==0:
return (-(b))/(2*a) , "est la solution à l'équation"
if delta<0:
return "l'equation n'admet pas de solution"
def resoudre_equation_2ndrg(x):
equ=x.replace(" ","")
a=recup_a(equ)
b=recup_b(equ)
c=recup_c(equ)
return CalcRacine(a,b,c)
print(resoudre_equation_2ndrg("2x²-9x-5"))