Python - jednoduchý cyklus while: Porovnání verzí

Z GeoWikiCZ
Bez shrnutí editace
mBez shrnutí editace
Řádek 13: Řádek 13:
  #!/usr/bin/python
  #!/usr/bin/python
   
   
  import math
  from math import sin
   
   
  s  = c = x = 0.4
  s  = c = x = 0.4
Řádek 25: Řádek 25:
   
   
  print s
  print s
  print math.sin(x)
  print sin(x)

Verze z 30. 11. 2005, 10:14

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

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 s
print sin(x)