请问这段代码哪里出错了?
代码:
def remove0ddNumbers(nums):
return [x for x in nums if x % 2 ==0]
nums = [int(x) for x in input("请输入若干个整数,中间用逗号分隔:").split()]
nums = remove0ddNumbers(nums)
print(nums)
怎样改可以得到下面图片中的运行结果?⬇️
请问这段代码哪里出错了?
代码:
def remove0ddNumbers(nums):
return [x for x in nums if x % 2 ==0]
nums = [int(x) for x in input("请输入若干个整数,中间用逗号分隔:").split()]
nums = remove0ddNumbers(nums)
print(nums)
怎样改可以得到下面图片中的运行结果?⬇️
input()接收的输入是字符串,无法用int()转换成整数。你需要用逗号分割:
int(x) for x in input().split(",")
望采纳,谢谢!