I found the a code in a website and I do not quite understand how it works or finds the upper and lower Fibonacci boundaries of a given number.
I want to understand how the code runs with an example like with x = 6
def fib_intervall(x):
""" returns the largest fibonacci
number smaller than x and the lowest
fibonacci number higher than x"""
if x < 0:
return -1
(old,new, lub) = (0,1,0)
while True:
if new < x:
lub = new
(old,new) = (new,old+new)
else:
return (lub, new)
while True:
x = int(input("Your number: "))
if x <= 0:
break
(lub, sup) = fib_intervall(x)
print("Largest Fibonacci Number smaller than x: " + str(lub))
print("Smallest Fibonacci Number larger than x: " + str(sup)