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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 2013/3/5 Ana Dion=EDsio : > 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 =3D (temp_-1)+1 > > it =3D 0 > temp =3D 3 > > it =3D 1 > temp =3D 3+1 > > it =3D 2 > temp =3D 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 =3D starting_value for i in range(number_of_iterations): tmp =3D tmp + 1 return tmp print(compute_iteratively(starting_value=3D7, number_of_iterations=3D3)) hth, vbr