Common small code

1, Fibonacci number (two elements and to determine the next number)
1  # 1,1,2,3,5,8,13,21,34,55,89 ...... 
2  # Method a: recursive 
. 3  DEF On Feb (n-):
 . 4      IF n-== 1 or n- 2 == :
 . 5          return . 1
 . 6      the else :
 . 7          return On Feb (. 1-n-) On Feb + (2-n- )
 . 8 n-=. 8
 . 9  Print (On Feb (n-))
 10  
. 11  
12 is  # method two: cycle 
13 is X, Y = 0,0
 14 n-. 8 =
 15  for I in Range (0, n-+. 1 ):
 16      IF i == 1 or i == 2:
17         x,y = 1,1
18     else:
19         x,y = y,x+y
20 print(y)
View Code

 

Guess you like

Origin www.cnblogs.com/hd-test/p/11309993.html