Creating a recursive function for calculating R = x - N * y, with conditions
<p>I wish to create a function for calculating R = x - N * y, where x and y are floats and N is the largest positive integer, so that x > N * y.</p>

<p>The function should only take the inputs of x and y.</p>

<p>I have previously created the function through a loop, but having trouble trying to convert it to recursion. My basic idea is something like:</p>

<pre><code>def florec(x, y):
    if x &gt; y:
        R = x - N * y
        florec(x, y_increased)
    return R
</code></pre>

<p>My problem is that I can not figure out how to code "y_increased", meaning, how I can update N to N+1, and then call upon florec(x, (N+1)*y). Then update N+1 to N+2 and call upon florec(x, (N+2)*y) and so on.</p>

<p>Feeling quite stuck currently, so any help at all to move forward would be appreciated.</p>

<p>If you're trying to return a value at each incrementation, you can use a generator function:</p>

<pre><code>def florec(x, y):
    N = 30  # not sure what you want N to start with
    while True:
        if x &gt; N * y:
            yield x - N * y
        else:
            break
        N += 1

for i in florec(332.432, 5.32):
    print i
</code></pre>

<p>Result:</p>

<pre><code>172.832
167.512
162.192
156.872
151.552
146.232
140.912
135.592
130.272
124.952
119.632
114.312
108.992
103.672
98.352
93.032
87.712
82.392
77.072
71.752
66.432
61.112
55.792
50.472
45.152
39.832
34.512
29.192
23.872
18.552
13.232
7.912
2.592
</code></pre>

python python-3.x