已知L=[1,2,4,3,5,9],选出L中的偶数,直到出现第1个奇数
L=[6,2,4,3,5,9]
L1=[]
for i in range(len(L)):
if L[i]%2==0:
L1.append(L[i])
print(L1)

L=[6,2,4,3,5,9]
unstop=1 #1的布尔值为True,借此做死循环
index=0
while unstop:
if L[index]%2==0:
print(L[index])
index=index+1
else:
unstop=0 #0的布尔值为False,借此终止循环
该文章展示了一段Python代码,其功能是从给定列表L中选取偶数并打印,直到遇到第一个奇数。代码使用了for循环和while循环两种不同的方法来实现这一逻辑。
1540

被折叠的 条评论
为什么被折叠?



