7.py 641 B

123456789101112131415161718192021222324
  1. import os
  2. def fibonacci(threshold):
  3. # Assign a start value for sequence
  4. current = 1
  5. previous = 0
  6. # Iterate fibonacci sequence as long as value is lesser than x
  7. while current <= threshold:
  8. # Print current value
  9. print(current)
  10. # Calculate new value from current value + previous value
  11. new = current + previous
  12. # Store the current value for next iteration
  13. previous = current
  14. # Store the new value as the current value
  15. current = new
  16. # Clear screen
  17. os.system("clear") # Mac or Linux
  18. # os.system("cls") # Windows
  19. # Call function fibonacci()
  20. fibonacci(1024)