Advertisement
Guest User

new

a guest
Oct 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. import os
  2.  
  3. f=open(r'fib_1610121189.txt','a',encoding='utf-8')
  4. def fib2(n):
  5.     if n == 1 or n == 2:
  6.         f.write(str(n))
  7.         f.write(":")
  8.         f.write("1")
  9.         print(1);
  10.         return
  11.     a = 1
  12.     b = 1
  13.     res = 0;
  14.     i=2
  15.     while i<n:
  16.         res = a + b
  17.         a = b
  18.         b = res
  19.         i+=1
  20.     f.write(str(n))
  21.     f.write(":")
  22.     f.write(str(res))
  23.     print(res)
  24.  
  25. i=1
  26. while i<=1000:
  27.     fib2(i)
  28.     i+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement