![]() ![]() |
| |||||||||
| Hotspots: Slides and Code TA Corner Comments? Announcements FAQ Static Webspace | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
def upDown(word):
if len(word)==1:
print word #Print #1
return
print word #Print #2
upDown(word[:-1])
print word #Print #3| If your ? is asking if it works, why don't you type it into JES, run it and see? Kelly Lyons |
| 9 lines are printed. One copy of downUp can print more than one line. -Blake O'Hare |
| A recursive function calls itself. This means that when you run downUp("hello"), it is going to create a new copy of downUp("ello") downUp("Hello") cannot finish running until downUp("ello") finish itself, so at that point there are 2 copies of the function running. But downUp("ello") will create a new copy which will create a new copy... until one of the copies contains a string of only one letter. Then, that copy will run the if statment, and not create a new copy. It will end, and then the copy that called it will end, and so on until the original call finishes. Part b is asking what is the largest number of copies running all at once. No, the answer is not 1. Kelly Lyons |
| Yes. Kelly Lyons |
| We won't necessarily comment on correct answers. But if you really want to make sure you're right, run downUp(hello) with the "Watcher" on. Everytime a new copy of def downUp(word) begins running, it will be listed, and none of them end until it returns. Summer McWilliams |