Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| teaching:progappchim:polynomes-2 [2012/10/25 09:51] – créée villersd | teaching:progappchim:polynomes-2 [2017/02/24 11:13] (Version actuelle) – villersd | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== | + | ====== |
| - | <sxh python; title : poly02-elementaire.py> | + | <code python poly02-elementaire.py> |
| - | # | + | #!/usr/bin/env python |
| # -*- coding: UTF-8 -*- | # -*- coding: UTF-8 -*- | ||
| - | """ | + | """ |
| - | des polynomes | + | écriture d'un programme pour évaluer |
| + | des polynômes | ||
| """ | """ | ||
| - | x=3. | + | x = 3. # variable en laquelle on veut évaluer le polynôme |
| - | a=[2.5, | + | a = [2.5, 6., 1.2, 3, 5] # la liste des coefficients, |
| - | n=len(a)-1 | + | n = len(a) - 1 # l' |
| - | print x,a,n | + | print(x,a,n) |
| - | p=0. | + | p = 0. # initialisation |
| for i in range(n+1): | for i in range(n+1): | ||
| - | p=p+a[i]*x**i | + | p = p + a[i] * x**i |
| + | |||
| + | print(p) | ||
| + | </ | ||
| + | |||
| + | <note tip> | ||
| + | |||
| + | Ce serait mieux de pouvoir évaluer le polynôme de manière " | ||
| - | print p | + | <note tip>La solution : utiliser les fonctions (def) en python...</note> |
| - | </sxh> | + | [[polynomes-3|Réponse à la page suivante !]] |