Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. def fib_intervall(x):
  2. """ returns the largest fibonacci
  3. number smaller than x and the lowest
  4. fibonacci number higher than x"""
  5. if x < 0:
  6. return -1
  7. (old,new, lub) = (0,1,0)
  8. while True:
  9. if new < x:
  10. lub = new
  11. (old,new) = (new,old+new)
  12. else:
  13. return (lub, new)
  14.  
  15. while True:
  16. x = int(input("Your number: "))
  17. if x <= 0:
  18. break
  19. (lub, sup) = fib_intervall(x)
  20. print("Largest Fibonacci Number smaller than x: " + str(lub))
  21. print("Smallest Fibonacci Number larger than x: " + str(sup)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement