簡體   English   中英

如何找到最大值

[英]How to find max value

我不知道代碼有什么問題。

def FunMax(theNumList):
    theMax = 0
    for Num in theNumList:
        if theMax < Num:
            theMax = Num
            return theMax

nList  = [100.11,123,456,234,111,321,60,99,88]

test4 = FunMax(nList)
print(test4)

return 語句處於錯誤的級別。 它必須在 for 循環之外,以便代碼可以遍歷整個列表。

一個警告是,如果所有值都 < 0,它不會返回列表的最大值。

   def FunMax(theNumList):
        theMax = 0

        for Num in theNumList:
            if theMax < Num:
                 theMax = Num
        return theMax

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM