Python - jednoduchý cyklus while: Porovnání verzí
mBez shrnutí editace |
m +kategorie programovani,python |
||
Řádek 5: | Řádek 5: | ||
# Fibonacciho posloupnost | # Fibonacciho posloupnost | ||
a = b = 1 | a = b = 1 | ||
print b | print "%d\n\n" % b | ||
while a < 100: | while a < 100: | ||
print a | print a | ||
Řádek 16: | Řádek 16: | ||
s = c = x = 0.4 | s = c = x = 0.4 | ||
x2 = x*x | x2 = x * x | ||
n = 1 | n = 1 | ||
while abs(c) > 1e-12: | while abs(c) > 1e-12: | ||
c = -c*x2/(n+1)/(n+2) | c = -c * x2 / (n + 1) / (n + 2) | ||
n = n + 2 | n = n + 2 | ||
s = s + c | s = s + c | ||
print s | print "%d\t%g\t%g" % (x, s, sin (x)) | ||
[[Kategorie:Programování]] | |||
[[Kategorie:Python]] |
Verze z 2. 9. 2006, 11:45
Ukázka použití jednoduchých cyklů
#!/usr/bin/python # Fibonacciho posloupnost a = b = 1 print "%d\n\n" % b while a < 100: print a a = a + b b = a - b
#!/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 "%d\t%g\t%g" % (x, s, sin (x))