Python 3.x return不会在python中完成程序

Python 3.x return不会在python中完成程序,python-3.x,return,Python 3.x,Return,虽然“if sound_str==None”条件有效,但程序不会结束并继续调用NowYouGotStepSize函数。我的返回函数有什么问题 def count_horses(sound_str,outputValue=None): print("sound_str",sound_str) stepStr = "" if sound_str == None: print("sound_str is =", sound_str)

虽然“if sound_str==None”条件有效,但程序不会结束并继续调用NowYouGotStepSize函数。我的返回函数有什么问题

def count_horses(sound_str,outputValue=None):
print("sound_str",sound_str)
stepStr = ""
if sound_str == None:
    print("sound_str is =", sound_str)
    return True
for eleman in sound_str:
    if str(eleman) != "0":
        stepStr += "1"works
        NowYouGotStepSize(sound_str,stepStr)
    else:
        stepStr += "0"
谢谢

编辑:你们中的一些人要求完整的代码,它没有完成,但仍然可能是你可以看到的错误。我正在试图解决卡塔。完整代码:

def NowYouGotStepSize(sound_str,stepStr):
arr=[]
arrStep=[]
outputValue = int(len(stepStr))
for eleman in sound_str:
    arr.append(eleman)
stepStr = stepStr*len(sound_str)
for eleman in stepStr:
    arrStep.append(eleman)
for i in range(0,len(arr)): # horse deleted
    arr[i] = int(arr[i])-int(arrStep[i])
stringWithoutaHorse=""
for eleman in arr:
    stringWithoutaHorse+=str(eleman)
if int(stringWithoutaHorse) == 0: #are there any 1 after delete horse
    return count_horses(None,outputValue) #no means no more horse steps
else:
    return count_horses(stringWithoutaHorse, outputValue) #yes means there are another horse

def count_horses(sound_str,outputValue=None):
    stepStr = ""
    if sound_str == None:
        return "12345"
    for eleman in sound_str:
        if str(eleman) != "0":
            stepStr += "1"
            NowYouGotStepSize(sound_str,stepStr) #horse step size detected
        else:
            stepStr += "0"
输入为:
打印(count_horses('0212030212'))#输出应为[2,2,3]

缩进错误
return
将始终导致函数退出。请修正你的缩进,以便清楚什么是函数的一部分,并包括一个缩进。您当前缺少代码,例如
NowYouGotStepSize
是否打印(“sound\u str is=,sound\u str)
execute?@Carcigenicate不总是这样,最后可能会有一个
要执行:D@timgeb它仍然会导致退出,只会有一些代码在之前执行。除非你在
finally
中有一个无限循环,在这种情况下,好的,你得到了我。