Summer 2006- Questions on Recursion
Questions?
def reverse (string):
if string == " ":
return " "
return reverse (string [1:]) + string [0]
| You need to check for an empty string. if string == "": There should be no space in between. You also need to fix the indentation. After that, it'll work. - Bobby Mathew |
def decreaseRed(alist):
if alist == []:
return
setRed(alist[0], getRed(alist[0]*.8)
decreaseRed(alist[1:])
| You need a closing ')' after the setRed statement. That should work provided the input is getPixels(picture). - Bobby Mathew |
def findlength (string):
if string == " ":
return 0
return len(string)
Link to this Page