Django Python

52 views
Skip to first unread message

hito koto

unread,
Jun 8, 2014, 11:06:18 AM6/8/14
to django...@googlegroups.com
Hi,

I want to change recursive definition from  function,

this code change to recursive definition, So how can i do to?

def foo(n, m):
 sum = 0
while m > 0:
sum = sum + n
m = m -1
return sum


Thiago borges dos reis

unread,
Jun 8, 2014, 11:20:47 AM6/8/14
to django...@googlegroups.com
without identaction !!! 

def foo(n, m):

 sum = 0
   while m > 0:
       sum = sum + n
       m = m -1
   return sum

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65921e2a-7b85-49fb-886b-90b847be8c06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thiago borges dos reis

unread,
Jun 8, 2014, 11:40:30 AM6/8/14
to django...@googlegroups.com
I'm sorry, i made a mistacke !

def foo(n,m):
...     sum = n
...     if m>1:
...             sum+=foo(n,m-1)
...     return sum

John

unread,
Jun 8, 2014, 2:32:34 PM6/8/14
to django...@googlegroups.com
This list is about the use of Django, a python framework for websites. You might get better help using a list which covers python more generally.

By the way, your function doesn't need recursion:

def foo(n,m):
  return m*n

John

hito koto

unread,
Jun 8, 2014, 5:12:04 PM6/8/14
to django...@googlegroups.com, john-...@martinhome.org.uk
Hi, Thiago borges dos reis 

Thank you!


2014年6月9日月曜日 3時32分34秒 UTC+9 John:

hito koto

unread,
Jun 8, 2014, 5:57:41 PM6/8/14
to django...@googlegroups.com
I have a question

This is why :
if m >1
and why you not use 0?

Thiago borges dos reis

unread,
Jun 8, 2014, 6:02:46 PM6/8/14
to django...@googlegroups.com
When you use m>0, you will do m+1 interaction .

Ex.:  foo(2,2): sum+=foo(2,1) <<<<---- last interaction


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

hito koto

unread,
Jun 8, 2014, 6:25:21 PM6/8/14
to django...@googlegroups.com
Thanks
Reply all
Reply to author
Forward
0 new messages