Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40540

Re: Recursive function

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.029
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'example:': 0.03; 'tmp': 0.07; 'calculates': 0.09; 'def': 0.10; 'skip:p 40': 0.15; 'iteration': 0.16; 'lot!': 0.16; 'temp': 0.16; 'parameters': 0.20; "i'd": 0.22; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; 'way?': 0.29; 'url:mailman': 0.29; 'probably': 0.29; 'e.g.': 0.30; 'url:python': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'clear': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'quite': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'hello!': 0.65; 'iterative': 0.84; 'temperature': 0.84; 'temperature,': 0.84; 'ana': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=OL3Uvv3MpHbdE8akIXod5sCePP9wQ99Yg3/KWIeeXfc=; b=CKuIQ6o72q5So0sP1fPaqLw/tZC+IClY6dUOUgH4lK8NiJkfxVjFzcSdkYvOsd/85z d7ZMKGtuLU6HWJcGxC3SaZLldqYXG/GRUokApRg69hNWTjHjG3uOdbJo8VFRMizxera4 g4WPXSx/I1xMODTg9LtPp/lpCNP+ozab07X+Uady9LkCDmlMl9hM0X8UseBWdHB8vGTJ Jx0kqQqDI3nq2Tcp8/BmxQSw37l5BOOiMkRPLlmNceIzTbwg+Oo6XFTYI3S5ASw5UTla rbZtpIgVNqBufJCnNUQ+WdiNQcHi4KMrPkt4VAker+8Um23po9/sAwBwuFaji7MAT8ei fsEg==
MIME-Version 1.0
X-Received by 10.224.185.148 with SMTP id co20mr40116640qab.94.1362499568705; Tue, 05 Mar 2013 08:06:08 -0800 (PST)
In-Reply-To <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com>
References <9ff73ed4-24cd-4a61-bb54-a67dd4a96ed0@r9g2000vbh.googlegroups.com>
Date Tue, 5 Mar 2013 17:06:08 +0100
Subject Re: Recursive function
From Vlastimil Brom <vlastimil.brom@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2892.1362499577.2939.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362499577 news.xs4all.nl 6958 [2001:888:2000:d::a6]:59975
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40540

Show key headers only | View raw


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 | NextPrevious in thread | Find similar | Unroll thread


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