Python - jednoduchý cyklus while

Z GeoWikiCZ

Ukázka použití jednoduchých cyklů

 #!/usr/bin/python
 
 # Fibonacciho posloupnost 
 a = b = 1
 print "%d\n" % b
 while a < 100:
    print a,
    a = a + b
    b = a - b
1

1 2 3 5 8 13 21 34 55 89
 #!/usr/bin/python
 
 from math import sin
 
 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 "%g\t%g\t%g" % (x, s, sin (x))
0.4       0.389418        0.389418

[ Zpět ]