I am having diffculty to understand this program
<p>i just came across this program and it seems to me very difficult to understand.
which is calculating the Fibonacci boundary for a positive number, returns a 2-tuple. The first element is the Largest Fibonacci Number smaller than x and the second component is the Smallest Fibonacci Number larger than x. The return value is immediately stored via unpacking into the variables lub and sup:</p>

<pre><code>def fib_intervall(x):
    """ returns the largest fibonacci
    number smaller than x and the lowest
    fibonacci number higher than x"""
    if x &lt; 0:
        return -1
    (old,new, lub) = (0,1,0)
    while True:
        if new &lt; x:
            lub = new 
            (old,new) = (new,old+new)
        else:
            return (lub, new)

while True:
    x = int(input("Your number: "))
    if x &lt;= 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))
</code></pre>

<p>I am trying to understand but i am lacking somewhere to understand it properly some big doubts:</p>

<p>why its returning -1 ?
what  this line  <code>(old,new, lub) = (0,1,0)</code> doing ?? 
what this piece of code intend to do ? </p>

<pre><code> if new &lt; x:
            lub = new 
            (old,new) = (new,old+new)
        else:
            return (lub, new)
</code></pre>

<p>How this assignment works in python ??   <code>(lub, sup) = fib_intervall(x)</code></p>

<p>overall if you explain whole program with deep explanation that would be so helpful.</p>

<p>Thanks in advance.</p>

<p>If you are wondering, the reason why it has two output parameters and one output is since two numbers are being generated inside the function itself.</p>

<p>If I have said program:</p>

<pre><code>def diameter(x):
    diameter = x * 2
    return diameter, x

diameter, radius = diameter(radius)
</code></pre>

<p>then two values, diameter and radius, are being returned, despite only one being inputted. To distinguish the inputted value, you can also rename it internally in the function, where x corresponds to the value of radius. This allows two variables to be defined from just one function.</p>

<p>Also, for future reference, if you need to swap two values, then you can use:</p>

<pre><code>value1, value2 = value2, value1
</code></pre>

<p>which is just a simple way to swap values in one line.</p>

python python-2.7 python-3.x