trinome2.py

Created by jilsaint90

Created on September 26, 2020

2.09 KB

Copie du script “trinôme” avec rajout de alpha et beta indiqués dans le texte final pour plus de compréhension (et pour un contrôle sans recherche :)


from math import *
from kandinsky import *
for i in range(12) : print("")
print("  --------------------------")
print("  Etude du trinome ax^2+bx+c")
print("   > Recherche des racines")
print("   > Alpha, beta")
print("   > Ecritures du trinome")
print("   > Coordonnees du sommet")
print("   > Allure de la parabole")
print("  --------------------------")
print("")
a=0
# Demande des coefficients du trinome
while a==0 : a=float(input('Coef a de x^2 = '))
b=float(input('Coef b de x   = '))
c=float(input('Constante c   = '))
for i in range(12) : print("")
# calcul de delta, alpha et beta
delta=b**2-4*a*c
alpha=-b/(2*a)
beta=-delta/(4*a)
#Affichage du texte selon
#les coefficients a, b et c
if delta == 0 :
  print("Delta = 0")
  print("Le trinome admet pour")
  print("racine : x0=-b/(2a)")
  x0=-b/(2*a)
  print("  x0 = ",x0)
  print("Sommet de la parabole :")
  print("  S(",x0,",0)")
elif delta > 0 :
  print("Delta = ",delta," > 0 donc les")
  print("racines de ce trinome sont :")
  x1=(-b-sqrt(delta))/(2*a)
  x2=(-b+sqrt(delta))/(2*a)
  print("  x1 = ",x1," et x2 = ",x2)
  print("Sommet de la parabole :")
  print("  S(",alpha,",",beta,")")
  print("alpha=", alpha, "et beta=", beta)
  print("Forme factorisee du trinome :")
  print(" ",a,"(x+",-x1,")(x+",-x2,")")
else :
  print ("Delta = ",delta)
  print("donc le trinome n'admet")
  print("pas de racines reelles")
  print("alpha=", alpha, "et beta=", beta)
  print("Sommet de la parabole :")
  print("  S(",alpha,",",beta,")")
print("Forme canonique du trinome :")
print(" ",a,"(x+",-alpha,")^2 +",+beta)
#Affichage de la parabole du trinome
choix=input('Tracer la courbe ? [o/n]')
if choix=='n' or choix=='8' :
  print("       - - - FIN - - -")
else :
  Xmin,Xmax,Ymin,Ymax=-10,10,-10,10
  red=color(255,0,0)
  black=color(0,0,0)
  for pixel_x in range(320):
    X=Xmin+pixel_x*(Xmax-Xmin)/319
    Y=a*X**2+b*X+c
    pixel_y=int((Y-Ymax)*221/(Ymin-Ymax))
    set_pixel(pixel_x,pixel_y,red)
  for x in range(320):
    y_0=int(Ymax*221/(Ymax-Ymin))
    set_pixel(x,y_0,black)
  for y in range(222):
    x_0=int(Xmin*319/(Xmin-Xmax))
    set_pixel(x_0,y,black)

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 cookies policy.