The exercise I have is asking me to determine if each number of a list is even or odd, then to return the result in a new list named is_even.
My code
num_lst = [3, 20, -1, 9, 10]
is_even = []
for n in num_lst:
if n % 2 == 0:
n = is_even.append(bool(n))
else :
is_even.append(bool(0))
print(is_even)
It works, but is there a better way to do it ?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…