davea at davea.name
Tue Mar 5 17:02:03 CET 2013
On 03/05/2013 10:32 AM, Ana Dionísio wrote:
> I have to make a script that calculates temperature, but one of the
> parameters is the temperature in the iteration before, for example:
> temp = (temp_-1)+1
> it = 0
> temp = 3
> it = 1
> temp = 3+1
> it = 2
> temp = 4+1
> How can I do this in a simple way?
> Thanks a lot!
Recursion only works when you have a termination condition. Otherwise,
it just loops endlessly (or more specifically until the stack runs out
of room). Still, you don't have a problem that even implies recursion,
For your simple case, there's a simple formula:
Methinks you have simplified the problem too far to make any sense.
temp = 3
for it in itertools.count():
temp += 1
print it, temp
Warning: that loop will never terminate.
Is this what you were looking for? It uses recursion, and I used <=0
for the termination condition.
if it <=0: return 3
More information about the Python-list