小编use*_*828的帖子

Python函数返回None(检查所有简单的解决方案,它们不起作用)

现在,我已经编写了Python的二进制搜索(版本2.7).有时,它工作正常,但有时它会返回None,尽管搜索的值在数组中.我已经尝试了解决这个问题的每个简单方法:我已经检查了函数返回的变量是否被定义,是否执行了返回语句所在的工作流的分支.和:变量定义,则分支执行.

这是代码:

def binarySearch( array, desiderata, iMin, iMax ):
# Returns the index of the first instance of what we search
print 'min'
print iMin
print 'max'
print iMax

# If our search array is empty
if ( iMin > iMax ):
    return None

midP = (iMin + iMax)/2
curre = tapeNr( array[midP][TAPE_NUMBER] )
final = tapeNr( desiderata )
print 'curre'
print curre
print 'final'
print final
print 'midP'
print midP

if ( curre < final …
Run Code Online (Sandbox Code Playgroud)

python binary return function

0
推荐指数
1
解决办法
266
查看次数

标签 统计

binary ×1

function ×1

python ×1

return ×1