techi3
In Runtime
- Messages
- 119
This prints:
# 1-Python is fun
# 2-Python is fun
# 3-Python is fun
# 4-Python is fun
# 5-Python is fun
I understand why it prints in reverse order but i'm confused of why it includes (# 5-Python is fun) since it seems to subtract 1 from 5 before it prints. The only thing I can think of is that once if finds num1 to be >= to 1 to be TRUE it goes strait to print then loops back up to subtract then test again, I remember reading about the "counterclockwise" motion in the "Think Python" book.
def moose(num1, str1):
if num1 >= 1:
moose(num1-1, str1)
print "# %d-%s" % (num1, str1)
else:
return
moose(5, "Python is fun")
# 1-Python is fun
# 2-Python is fun
# 3-Python is fun
# 4-Python is fun
# 5-Python is fun
I understand why it prints in reverse order but i'm confused of why it includes (# 5-Python is fun) since it seems to subtract 1 from 5 before it prints. The only thing I can think of is that once if finds num1 to be >= to 1 to be TRUE it goes strait to print then loops back up to subtract then test again, I remember reading about the "counterclockwise" motion in the "Think Python" book.
def moose(num1, str1):
if num1 >= 1:
moose(num1-1, str1)
print "# %d-%s" % (num1, str1)
else:
return
moose(5, "Python is fun")