我正在尝试编写一个函数,使用while循环
返回列表中的第一个偶数def first_even(list):
while i%2 !=0: #I'm not sure if this is a good start for the while loop, but I think I'm supposed to use something%2...
#no idea what to do here
答案 0 :(得分:1)
一种优秀且非常短的编码风格将是:
for i in list:
if i%2 == 0:
return i