Python Forum
Python recursive functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python recursive functions
#6
Another example of recursion:
Print the series of squares of a number repeatedly until the number is over 10,000, greatest to smallest.
def recurse(number):
    if number < 10000 :
        recurse(number*number)
    print(number)
    return

recurse(2)
Output:
65536 256 16 4 2
Best non-contrived example of recursion I can think of is Towers of Hanoi.
Reply


Messages In This Thread
Python recursive functions - by Ayman_2001 - Jun-24-2020, 08:45 AM
RE: Python recursive functions - by ndc85430 - Jun-24-2020, 10:14 AM
RE: Python recursive functions - by jefsummers - Jun-24-2020, 11:32 AM
RE: Python recursive functions - by Ayman_2001 - Jun-24-2020, 01:23 PM
RE: Python recursive functions - by deanhystad - Jun-24-2020, 02:11 PM
RE: Python recursive functions - by jefsummers - Jun-24-2020, 05:40 PM
RE: Python recursive functions - by ndc85430 - Jun-24-2020, 07:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Recursive functions Ayman_2001 3 2,251 Jun-27-2020, 03:46 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020