max()不返回最大数

时间:2018-10-26 17:28:31

标签: python max

我有一个函数,可以找到字符串中的奇数,并将它们添加到奇数列表中,然后在列表上使用max()来找到最大的奇数,但它似乎将自身限制为99,例如。

firebase.auth.Auth.Persistence.Local

现在,如果我输入def largest_odd(): userInput = input(' enter 10 integers separated by a space').split(' ') oddList = [] for x in userInput: if int(x) % 2 > 0: oddList.append(x) print(x, ' is odd') else: print(x, ' is not odd') return max(oddList) largest_odd() ,它将返回最高的9。

如果我输入'1 2 3 4 5 6 7 8 9'

它将返回'1 2 3 4 5 20175'作为最高值。

1 个答案:

答案 0 :(得分:1)

这是您的更正代码:

def largest_odd():
    userInput = input(' enter 10 integers separated by a space').split(' ')
    oddList = []

    for x in userInput:
        if int(x) % 2 > 0:
            oddList.append(int(x))
            print(x, ' is odd')
        else:
            print(x, ' is not odd')

    return max(oddList)

print(largest_odd())