Python - jednoduchý cyklus while: Porovnání verzí
mBez shrnutí editace |
Bez shrnutí editace |
||
Řádek 15: | Řádek 15: | ||
import math | import math | ||
s = c = x = 0.4 | s = c = x = 0.4 | ||
n = 1 | x2 = x*x | ||
n = 1 | |||
while abs(c) > 1e-12: | while abs(c) > 1e-12: | ||
c = -c* | c = -c*x2/(n+1)/(n+2) | ||
n = n + 2 | n = n + 2 | ||
s = s + c | s = s + c |
Verze z 29. 11. 2005, 23:11
Ukázka použití jednoduchých cyklů
#!/usr/bin/python # Fibonacciho posloupnost a = b = 1 print b while a < 100: print a a = a + b b = a - b
#!/usr/bin/python import math s = c = x = 0.4 x2 = x*x n = 1 while abs(c) > 1e-12: c = -c*x2/(n+1)/(n+2) n = n + 2 s = s + c print s print math.sin(x)