举个例子
“A
arr=range(1,10)
skip=[3,5]
for i in arr:
for s in skip:
if i % s ==0:
continue
print(i)
本意是 被3或者5整除的数不打印, 但是这样写 貌似是跳过 skip的列表,怎么样满足条件后跳过arr
1
rrfeng 2014-10-24 20:26:40 +08:00
break
|
2
rrfeng 2014-10-24 20:28:39 +08:00
哦看错了……
|
3
skydiver 2014-10-24 20:36:19 +08:00
无所谓,print放里面就行了
|
4
yuelang85 2014-10-24 21:19:14 +08:00
打标记。
第一层循环一开始把flag设为0,第二层循环遇到条件就把flag设成1,紧接着break。这样就跳到了第一层循环,判断flag为1,continue。 for i in xrange(1, 10): >>>>flag = 0 >>>>for x in xrange(1, 10): >>>>>>>>if x == 2: >>>>>>>>>>>>flag = 1 >>>>>>>>>>>>break >>>>if flag == 1: >>>>>>>>continue |
5
picasso250 2014-10-24 21:52:56 +08:00
def can_print(i):
>>>>for s in skip: >>>>>>>>if i % s == 0: return False >>>>return True for i in arr: >>>>if can_print(i): print(i) if you find a way hard, then u might choose the wrong way |