Guest User

Untitled

a guest
Nov 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. # creating a list of fibonacci numbers (capped at 20)
  2. # adds the two previous numbers to equal the next
  3. def get_fib_list_length():
  4. return 20
  5. def generate_fib(num):
  6. result = []
  7.  
  8. for n in range(num):
  9.  
  10. if n == 0:
  11. result.append(0)
  12.  
  13. elif n == 1:
  14. result.append(1)
  15.  
  16. # else add n[index n-2] + n[index n-1]
  17. else:
  18. value = result[n-2] + result[n - 1]
  19. result.append(value)
  20. return result
  21.  
  22. def display_fibs(fibs):
  23. for fib in fibs:
  24. print(fib)
  25.  
  26. def main():
  27. fib_limit = get_fib_list_length()
  28. fibs = generate_fib(fib_limit)
  29. display_fibs(fibs)
  30.  
  31. main()
Add Comment
Please, Sign In to add comment