Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40540
| References | <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com> |
|---|---|
| Date | 2013-03-05 17:06 +0100 |
| Subject | Re: Recursive function |
| From | Vlastimil Brom <vlastimil.brom@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2892.1362499577.2939.python-list@python.org> (permalink) |
2013/3/5 Ana Dionísio <anadionisio257@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Recursive function Ana Dionísio <anadionisio257@gmail.com> - 2013-03-05 07:32 -0800
Re: Recursive function Dave Angel <davea@davea.name> - 2013-03-05 11:02 -0500
Re: Recursive function Ana Dionísio <anadionisio257@gmail.com> - 2013-03-05 08:15 -0800
Re: Recursive function Ana Dionísio <anadionisio257@gmail.com> - 2013-03-05 08:15 -0800
Re: Recursive function Neil Cerutti <neilc@norwich.edu> - 2013-03-05 19:05 +0000
Re: Recursive function Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-03-05 17:06 +0100
csiph-web