====== Différences ======
Cette page vous affiche les différences entre la révision choisie et la version actuelle de la page.
cours:activite1:python [2013/10/28 16:11] r.doiteau [Fonction] |
cours:activite1:python [2019/05/11 14:35] (Version actuelle) |
||
---|---|---|---|
Ligne 508: | Ligne 508: | ||
</code> | </code> | ||
- | === Cube === | + | === Volume sphere === |
<code=python> | <code=python> | ||
+ | from math import pi | ||
+ | def cube(x): | ||
+ | return x**3 | ||
+ | |||
+ | def volume_sphere (z): | ||
+ | return 4.0*pi*cube(z)/3.0 | ||
+ | |||
+ | |||
+ | rayon = float (input("entrer un rayon : ")) | ||
+ | |||
+ | print('Le volume de la sphére de rayon ',round(rayon,0),'est de',round(volume_sphere(rayon),0)) | ||
</code> | </code> | ||
+ | === Equation === | ||
+ | <code=python> | ||
+ | ########################################################## | ||
+ | # fonction qui retourne f(x)=2x3+x-5 # | ||
+ | ########################################################## | ||
+ | | ||
+ | def maFonction(x): | ||
+ | return 2*x**3 + x-5 | ||
+ | |||
+ | def tabuler(fonction, bornInf, bornSup, nombrePas): | ||
+ | h=(bornSup-bornInf)/float(nombrePas) | ||
+ | x=bornInf | ||
+ | while x< bornSup: | ||
+ | y=fonction(x) | ||
+ | print("f({:.2f}) = {:.3f}".format(x, y)) | ||
+ | x+=h | ||
+ | |||
+ | |||
+ | |||
+ | borne_inf = float(input("Borne inférieur : ")) | ||
+ | borne_sup = float(input("Borne supérieur : ")) | ||
+ | nbPas = int(input("Nombre de pas: ")) | ||
+ | tabuler(maFonction, borne_inf, borne_sup, nbPas) | ||
+ | |||
+ | </code> | ||