Linked Questions

Popular Questions

Recursive python call does not verify all the options

Asked by At

Build a recursive function that verifies that for each i<len(lis)/2 : lis[i]+lis[len(lis)-i-1] = x

def controlTest(list,x):
#@param list: list of integers
#@param x: integer
#@return: bool
 for i in range(0,len(list)/2):
  if list[i]+list[len(list)-i-1]==x:  
   return controlTest(list[1:len(list)-1],x)
  else:
   return list 

I expect the output of this function to be an empy list [], but the for-loop jumps the steps of the recursive call

Examples: if list= [1, 5, 3, 6, 4, 8] and x = 9, the function returns an empty list [] because 1+8 = 5+4 = 3+6 = 9

Related Questions