0
使用函数print_even_values输入整数列表并打印列表中的每个偶数。调用print_even_values([2,8,1,9,0,19,24])将产生此输出在外壳窗口:函数定义:从整数列表中返回偶数的列表
我的做法是:
def print_even_numbers(n:list) -> list:
'''Return a list of even numbers given a list of integers'''
for x in list:
if x % 2 == 0:
return(x)
assert print_even_numbers([2, 4, 2, 4, 5, 6]) == [2, 4, 2, 4, 6]
assert print_even_numbers([4, 1, 3, 2, 5, 9]) == [4, 2]
,但出现错误。另外,如何让我的输出与问题类似? (即
[2, 4, 2, 4, 6]
与(单独行)
2
4
2
4
6
格式化结果 – Phani