On Sun, 2014-02-09 at 13:56 -0500, Dave Angel wrote:
[…]
> Not as bad as attributing that code to me.
Apologies for that implication, bad editing on my part, I should have
retained the link to the author.
--
Russel.
=
Dr
Russel Winder Wrote in message:
> On Thu, 2014-02-06 at 18:06 -0500, Dave Angel wrote:
> [â¦]
>>
>> Code:
>> def fib2(n):
>> if n==1:
>> return 1
>>
>> elif n==2:
>> return 1
>> else:
>> return fib2(n-2) +fib2(n-1)
> [â¦]
>
> I suggest it
On Thu, 2014-02-06 at 18:06 -0500, Dave Angel wrote:
[…]
>
> Code:
> def fib2(n):
> if n==1:
> return 1
>
> elif n==2:
> return 1
> else:
> return fib2(n-2) +fib2(n-1)
[…]
I suggest it also be pointed out that this form is algorithmical
On 08/02/2014 10:06, rakesh sharma wrote:
Please do not top post on this list.
I got my definition wrong
the code should be more like this
def fib(n):
if n==0:
return
What does the above line return? As others have already said what
happens if n is negative?
elif n==1:
return 1
elif n=
ubject: Re: [Tutor] learning recursion
> From: denis.heidtm...@gmail.com
> To: rakeshsharm...@hotmail.com
> CC: da...@davea.name; tutor@python.org
>
> On Fri, Feb 7, 2014 at 9:05 PM, rakesh sharma
> wrote:
> > Hi
> >
> > Shouldn't your code be like thi
Hi
I guess I need to revisit my maths lessons.Thank you for correcting me.
thanks,rakesh
> From: d...@hashcollision.org
> Date: Sat, 8 Feb 2014 00:20:19 -0800
> Subject: Re: [Tutor] learning recursion
> To: rakeshsharm...@hotmail.com
> CC: da...@davea.name; tutor@python.org
>
On Fri, Feb 7, 2014 at 9:05 PM, rakesh sharma
wrote:
> Hi
>
> Shouldn't your code be like this
>
> def fib(n):
> if n==0:
> return 0
> else:
> return n + fib(n-1)
Hi Rakesh,
Unfortunately, no, because this computes a slightly different
function: the triangular numbers! :P
That is, your funct
On Fri, Feb 7, 2014 at 9:05 PM, rakesh sharma
wrote:
> Hi
>
> Shouldn't your code be like this
>
> def fib(n):
> if n==0:
> return 0
> else:
> return n + fib(n-1)
>
> this works
>
for i in range(4):
> print fib(i)
>
> 0
> 1
> 3
> 6
interesting, but the Fibonacci sequence is 1,1,2,3,5,8,
014 18:06:41 -0500
> Subject: Re: [Tutor] learning recursion
>
> Denis Heidtmann Wrote in message:
> >
> >
> Please post in text, not html. Your posting program loses the
> indentation in the text view, which is what most people
> see.
>
> Code:
> def
Denis Heidtmann Wrote in message:
>
>
Please post in text, not html. Your posting program loses the
indentation in the text view, which is what most people
see.
Code:
def fib2(n):
if n==1:
return 1
elif n==2:
return 1
else:
On Thu, Feb 6, 2014 at 11:28 AM, Denis Heidtmann
wrote:
for i in range(4):
> ... print fib2(i)
> ...
>
> The above results in an error:
Because fib2(0) recurses infinitely, and i's first value is 0.
-- Devin
___
Tutor maillist - Tutor@python
Ah. Consider what range(4) looks like. It's similar to the sequence:
[0, 1, 2, 3]
What happens when you do fib2(0)?
:P
Here's your program (modified with a correction) on repl.it, for convenience:
http://repl.it/O30
___
Tutor maillist -
On 2014-02-06, Denis Heidtmann wrote:
> Running python 2.7 on Ubuntu 12.04
>
> Code:
> def fib2(n):
> if n==1:
> return 1
> elif n==2:
> return 1
> else:
> return fib2(n-2) +fib2(n-1)
Something ate your leading spaces. Keep in mind that that makes
most Python code unrecoverably corrupt. When shar
Denis Heidtmann wrote:
> Running python 2.7 on Ubuntu 12.04
>
> Code:
> def fib2(n):
> if n==1:
> return 1
> elif n==2:
> return 1
> else:
> return fib2(n-2) +fib2(n-1)
>
> The above works:
>
fib2(7)
> 13
fib2(4)
> 3
>
for i in range(4):
> ... print fib2(i)
> ...
>
> The ab
Running python 2.7 on Ubuntu 12.04
Code:
def fib2(n):
if n==1:
return 1
elif n==2:
return 1
else:
return fib2(n-2) +fib2(n-1)
The above works:
>>> fib2(7)
13
>>> fib2(4)
3
>>> for i in range(4):
... print fib2(i)
...
The above results in an error:
Traceback (most recent call last):
File
15 matches
Mail list logo