Python recursive function doesn't return

前端 未结 3 834
情书的邮戳
情书的邮戳 2021-01-23 04:58

I\'m trying to sharpen my noob Python skills by trying a problem my son has in his college CS class. The goal is to create a function that uses recursion to process a list. The

3条回答
  •  逝去的感伤
    2021-01-23 05:31

    You aren't returning in your general case. Try:

    def RecursiveProcess(ListIn2, target): 
        if target > -1:
            ListIn2[target] = ListIn2[target] + ListIn2[target+1]  
            ListIn2 = RecursiveProcess(ListIn2, target-1) 
            return ListIn2 #Actually need to return in the general case
        else:
            return ListIn2  
    

提交回复
热议问题