I've been working on a problem I don't understand why the recursive function step returns None?
here is the code :
import sys
def minIndx(list):
x=10
indx=0
for i in range(len(list)):
if (list[i]<x):
x=list[i]
indx=i
return indx
def steps(arr,sum1,sum2,x):
i = minIndx(arr)
del arr[i]
sum1 = sum(arr)
if (sum1 + 9*x >= sum2):
return x
else: steps(arr,sum1,sum2,x+1)
s=input()
digits1=[]
digits2=[]
for i in range(len(s)):
if (i>2):break
digits1.append(int(s[i]))
for i in range(len(s)):
if (i<3):continue
digits2.append(int(s[i]))
sumLeft = sum(digits1)
sumRight = sum(digits2)
print(steps(digits1,sumLeft,sumRight,1))
for the test case : 123456, the step function prints None as well as the print function
It could be because you're not returning your recursive call. What is your expected output here? When I return the recursive call to steps I get a value of 2 for an input of 123456.