from math import sqrt def mini(tab): minimum=tab[0] for element in tab: if elementmaximum: maximum=element return maximum def somme(tab): somme=0 for element in tab: somme+=element return somme def somme_des_carres(tab): somme=0 for element in tab: somme+=element**2 return somme def moyenne(tab): return somme(tab)/len(tab) def etendue(tab): return maxi(tab)-mini(tab) def effectif_total(tab): return len(tab) def variance(tab): somme=0 moy=moyenne(tab) for element in tab: somme+=(element-moy)**2 return somme/len(tab) def ecart_type(tab): return sqrt(variance(tab)) def ecart_type_echantillon(tab): L=len(tab) return sqrt(variance(tab)*L/(L-1)) def tri_croissant(tab): sortie=tab sortie.sort() return sortie def Q1(tab): L=len(tab) if L%2==0: return tri_croissant(tab)[len(tab)//4-1] else: return tri_croissant(tab)[len(tab)//4] def Q3(tab): L=len(tab) if L%2==0: return tri_croissant(tab)[3*len(tab)//4-1] else: return tri_croissant(tab)[3*len(tab)//4] def mediane(tab): L=len(tab) sortie=tri_croissant(tab) if L%2==0: return moyenne([sortie[L//2-1],sortie[L//2]]) else: return sortie[L//2] def ecart_interquartile(tab): return Q3(tab)-Q1(tab) def Stats_1Var(tab): print("Effectif total :"+str(effectif_total(tab))) print("Minimum :"+str(mini(tab))) print("Maximum :"+str(maxi(tab))) print("Étendue :"+str(etendue(tab))) print("Moyenne :"+str(moyenne(tab))) print("Écart type :"+str(ecart_type(tab))) print("Variance :"+str(variance(tab))) print("Premier quartile :"+str(Q1(tab))) print("Troisième quartile :"+str(Q3(tab))) print("Médiane :"+str(mediane(tab))) print("Écart interquartile :"+str(ecart_interquartile(tab))) print("Somme :"+str(somme(tab))) print("Somme des carrés :"+str(somme_des_carres(tab))) print("Écart type échantillon :"+str(ecart_type_echantillon(tab))) def boite_a_moustaches(tab): import matplotlib.pyplot as plt plt.clf() plt.boxplot([mini(tab),Q1(tab),mediane(tab),Q3(tab),maxi(tab)]) plt.ylim(mini(tab)-2,maxi(tab)+2) plt.savefig('SimpleBoxPlot.png') plt.show()