Skip to content

Instantly share code, notes, and snippets.

@FaustinM
Last active January 2, 2021 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FaustinM/7b80af20eaf2810bafabf7e0ca3f70b3 to your computer and use it in GitHub Desktop.
Save FaustinM/7b80af20eaf2810bafabf7e0ca3f70b3 to your computer and use it in GitHub Desktop.
Polynome du second degrès
from math import *
from kandinsky import *
for i in range(12) : print("")
print(" --------------------------")
print("Etude d'un polynome ax^2+bx+c")
print(" --------------------------")
print("")
a=0
# Demande des coefficients du trinome
while a==0 : a=float(input('Valeur de a ? '))
b=float(input('Valeur de b ? '))
c=float(input('Valeur de c ?'))
for i in range(12) : print("")
delta=b**2-4*a*c
print("Forme developpe = {}x^2+{}x+{}".format(a, b, c))
print("Delta = {}**2-4{}*{}".format(b, a, c))
print("Delta = {}".format(delta))
# calcul de delta, alpha et beta
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("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("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 : ## Partie pour tracer le graphique vous n'êtes pas obliger de la comprendre
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment