我有一个函数,可以找到字符串中的奇数,并将它们添加到奇数列表中,然后在列表上使用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'
作为最高值。
答案 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())