break跳出循环的位置重要吗
如下 sum = 0 sum = 0 x = 1 x = 1 n = 1 n = 1 while True: while True: if n > 20: sum = sum + x break x = x * 2 sum = sum + x n = n + 1 x = x * 2 if n > 20: n = n + 1 break print sum print sum 前面的是参考答案,后面是我自己写的,一样算成功
如下 sum = 0 sum = 0 x = 1 x = 1 n = 1 n = 1 while True: while True: if n > 20: sum = sum + x break x = x * 2 sum = sum + x n = n + 1 x = x * 2 if n > 20: n = n + 1 break print sum print sum 前面的是参考答案,后面是我自己写的,一样算成功
2019-01-07
举报