====== 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 15:58] r.doiteau [Fonction] |
cours:activite1:python [2019/05/11 14:35] (Version actuelle) |
||
|---|---|---|---|
| Ligne 338: | Ligne 338: | ||
| </code> | </code> | ||
| - | === exemple turtle === | + | === Turtle === |
| <code=python> | <code=python> | ||
| Ligne 485: | Ligne 485: | ||
| + | === Base,début,inc === | ||
| + | <code=python> | ||
| + | def table(base, debut, fin,inc): | ||
| + | n = debut | ||
| + | while n <= fin: | ||
| + | print (n,'x', base,'=', n * base) | ||
| + | n += inc | ||
| + | # exemple d’appel : | ||
| + | table(7, 2, 11,1) | ||
| + | </code> | ||
| + | |||
| + | === Cube === | ||
| + | <code=python> | ||
| + | def cube(litre): | ||
| + | return litre**3 | ||
| + | |||
| + | print (cube (100),"Litres") | ||
| + | |||
| + | </code> | ||
| + | |||
| + | === Volume sphere === | ||
| + | <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> | ||
| + | |||
| + | === 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> | ||