【发布时间】:2021-12-10 19:55:45
【问题描述】:
在字符串格式化期间出现并非所有参数都转换的错误
def even_odd_lambda(list_object):
#odd_ctr = list(filter(lambda x: (x%2 != 0) , list_1))
#even_ctr = list(filter(lambda x: (x%2 == 0) , list_1))
odd_ctr = len(list(filter(lambda x: (x%2 != 0) , list_object)))
even_ctr = len(list(filter(lambda x: (x%2 == 0) , list_object)))
return [odd_ctr, even_ctr]
if __name__ == '__main__':
a=input("Add list elements seperated by space ").split(' ')
output = even_odd_lambda(a)
print("\nNumber of even numbers in the above array: ", output[1])
print("\nNumber of odd numbers in the above array: ", output[0])
【问题讨论】:
-
x是一个字符串,所以%是printf-style formatting 不是模数。 -
这能回答你的问题吗? Get a list of numbers as input from the user
标签: python python-3.x