2013-09-30 58 views

回答

0

你需要在底部返回true (另外請注意,對於我來說,如果東西是beginRange或endRange,我會考慮在裏面,所以我會做<和>而不是< =和> =),並且那很重要......你可能想要返回真正的東西,否則就是假。 (另請注意,它應該是假/真不是假/真)

2

false應該False,並在年底返回True否則函數將返回None(默認的返回值),如果兩個條件都False

def outside(testnum, beginRange, endRange): 
    if testnum <= beginRange: 
     return False 
    if testnum >= endRange: 
     return False 
    return True 

或者乾脆:

def outside(testnum, beginRange, endRange): 
    return beginRange < testnum < endRange 
1

下一個簡單襯裏可在這裏工作:

def inside(testnum, lowthreshold, highthreshold): 
    return lowthreshold <= testnum <= highthreshold 

def outside(testnum, lowthreshold, highthreshold): 
    return not (lowthreshold <= testnum <= highthreshold) 

編輯:意識到我是表明裏面,不在外面。使它更清晰。

相關問題