equasolve.py

Created by golem64

Created on October 12, 2020

1.2 KB

Solveur d’équation permettant de trouver x0 ou x1 et x2 (avec Δ si nécessaire). Supporte également les chiffres en division (exemple : c=1/3)


from math import *
import ion
from ion import *

def racinex1(a,b,c):
  for i in range(-2,3):
    if (a*(i)**2)+(b*i)+c==0:
      return i
  return 3

a="0"
while a=="0":
  a=input("a=")
b=input("b=")
c=input("c=")
a=a.split("/")
if len(a)==2:
  a=float(a[0])/float(a[1])
else:
  a=float(a[0])
b=b.split("/")
if len(b)==2:
  b=float(b[0])/float(b[1])
else:
  b=float(b[0])
c=c.split("/")
if len(c)==2:
  c=float(c[0])/float(c[1])
else:
  c=float(c[0])
x1=racinex1(a,b,c)
if x1==3:
  print("Aucune racine évidente.")
  print("Continuer quand même en")
  print("sortant de R ?")
  print("(EXE=Oui, SUPPRIMER=Non)")
  rep=0
  while rep==0:
    if ion.keydown(KEY_EXE):
      rep=1
    if ion.keydown(KEY_BACKSPACE):
      rep=2
  if rep==1:
    delta=(b**2)-(4*(a*c))
    if delta<0:
      print("Il n'existe aucune racine")
      print("pour la fonction donnée.")
    else:
      if delta==0:
        x0=(-b)/(2*a)
        print("Δ="+str(delta))
        print("x0="+str(x0))
      else:
        x1=(-b-(sqrt(delta)))/(2*a)
        x2=(-b+(sqrt(delta)))/(2*a)
        print("Δ="+str(delta))
        print("x1="+str(x1))
        print("x2="+str(x2))
else:
  x2=(c/a)/x1
  print("x1="+str(x1))
  print("x2="+str(x2))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.