On Fri, 11 Jan 2008 06:30:04 -0600, Nick Craig-Wood wrote:
> HYRY <[EMAIL PROTECTED]> wrote:
>> def bears (n):
>> if n==42:
>> return True
...
>> return False
>
> Almost but you missed a case...
Why are you people doing the OP's homework for him? And then DEBUGGING it
as wel
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Tom_chicollegeboy
> Sent: Friday, January 11, 2008 3:30 AM
> To: python-list@python.org
> Subject: python recursive function
>
> Now, you are to write a program tha
On 11 Jan, 08:30, Tom_chicollegeboy <[EMAIL PROTECTED]> wrote:
> here is what I have to do:
>
> This question involves a game with teddy bears. The game starts when I
> give you some bears. You then start giving me back some bears, but you
> must follow these rules (where n is the number of bears t
HYRY <[EMAIL PROTECTED]> wrote:
> def bears (n):
> if n==42:
> return True
> if n%5==0:
> if bears(n-42):
> return True
> if n%2==0:
> if bears(n/2):
> return True
> if n%3==0 or n%4==0:
> one = (n%10)
> two
Duncan Booth a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]>
> wrote:
>
>> You want:
>>return bears(n - 42)
>
> Actually, no he doesn't. He needs to explore all options when the first
> attempt fails.
Possibly - I didn't bother checking the algorithm correctness, just
pointed
> def bears (n):
> if n==42:
> return True
> if n%5==0:
> bears(n-42)
> if n%2==0:
> bears(n/2)
> if n%3==0 or n%4==0:
> one = (n%10)
> two = ((n%100)/10)
> if one!=0 and two!=0:
> bears(n-(one*two))
> return False
>
>
> Stylistically I prefer 'if not n % 5', looks neater.
> As for your assignment, the hardest task will be creating an effective
> method of ensuring you recurse through all possibilities.
I was chatting to a friend about the 'if not n % 5' and while I am
happy to use it saying that when 5 % 5 is F
On Jan 11, 10:30 am, Tom_chicollegeboy <[EMAIL PROTECTED]> wrote:
> here is what I have to do:
>
> This question involves a game with teddy bears. The game starts when I
> give you some bears. You then start giving me back some bears, but you
> must follow these rules (where n is the number of bear
Bruno Desthuilliers <[EMAIL PROTECTED]>
wrote:
> You want:
>return bears(n - 42)
Actually, no he doesn't. He needs to explore all options when the first
attempt fails. But I'm not going to write his homework for him.
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 11, 9:46 am, Gary Herron <[EMAIL PROTECTED]> wrote:
> Tom_chicollegeboy wrote:
> > here is what I have to do:
>
> > This question involves a game with teddy bears. The game starts when I
> > give you some bears. You then start giving me back some bears, but you
> > must follow these rules (w
Gary Herron a écrit :
> Tom_chicollegeboy wrote:
>> here is what I have to do:
>>
>> This question involves a game with teddy bears. The game starts when I
>> give you some bears. You then start giving me back some bears, but you
>> must follow these rules (where n is the number of bears that you
>
Tom_chicollegeboy a écrit :
(snip)
> As you see my program must use recursion.
It's conceptually easier to express using recursions - but every
recursion-based algorithm can be rewritten to use iteration (and
vice-versa).
> I came up with this idea but I am not sure if its right or are there
>
Tom_chicollegeboy wrote:
> here is what I have to do:
>
> This question involves a game with teddy bears. The game starts when I
> give you some bears. You then start giving me back some bears, but you
> must follow these rules (where n is the number of bears that you
> have):
>
This sounds very
here is what I have to do:
This question involves a game with teddy bears. The game starts when I
give you some bears. You then start giving me back some bears, but you
must follow these rules (where n is the number of bears that you
have):
If n is even, then you may give back exactly n/2 bears.
14 matches
Mail list logo