Try to write upDown() both recursively and without recursion. Which is easier? Why?
Try writing upDown():
>>> upDown("Hello")
Hello
Hell
Hel
He
H
He
Hel
Hell
Hello
Note: Given that output, one can presume that they were either printed out, or are one string with new line characters at the end of each line.
Recursively:
```
def upDown(str):
print str
if len(str)>1:
upDown(str[0:len(str)-1])
print str
```
Without Recursion:
```
def upDown(str):
origStr = str
while len(str)>0:
print str
str = str[0:len(str)-1]
while len(str)
print str
```
Whether you think that doing this with or without recursion is easier largely depends on your familiarity with recursion. I found the recursive version much easier as there was less code to think through.
You might also like to view...
Who is responsible for guaranteeing the integrity and accuracy of the evidence gathered in criminal or civil court cases?
What will be an ideal response?
A quick way to add buttons to your document is by using one of the predesigned buttons in the Buttons ____.
A. glossary B. dictionary C. archive D. library
The letter D at the beginning of a function identifies to Excel that a ________ range will be used in the formula
A) table B) row C) column D) database
Use ____ to secure and catalog the evidence contained in large computer components.
a. Hefty bags b.regular bags c. paper bags d.evidence bags