Recursive function
Vlastimil Brom
vlastimil.brom at gmail.com
Tue Mar 5 11:06:08 EST 2013
2013/3/5 Ana DionĂsio <anadionisio257 at gmail.com>:
> Hello!
>
> 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!
> --
> http://mail.python.org/mailman/listinfo/python-list
Hi,
it is not quite clear from the examples, what should be achieved (I
guess, the actual computation is probably mor complex).
I'd probably approach an iterative computation iteratively, rather
than recursively;
e.g. simply:
def compute_iteratively(starting_value, number_of_iterations):
tmp = starting_value
for i in range(number_of_iterations):
tmp = tmp + 1
return tmp
print(compute_iteratively(starting_value=7, number_of_iterations=3))
hth,
vbr
More information about the Python-list
mailing list