我想解决这个问题是最简单的方法,我是一个初学者,这是我被问到的问题和代码:
程序逻辑选择。考虑下面的代码,它使用while循环和found标志搜索2的幂次列表,以查找2的五次幂(32),它存储在一个名为电源.py. 在
L = [1, 2, 4, 8, 16, 32, 64]
X = 5
found = False
i = 0
while not found and i < len(L):
`if 2 ** X == L[i]:`
found = True
else:
i = i+1
if found:
('at index', i)
else:
print(X,'not found')
它要我做的是几个问题,但第一个问题让我很困惑
首先,用while循环else子句重写代码,以消除found标志和final if语句。在
如有任何帮助,不胜感激。谢谢。在
Python附带了batteries
使用
index
方法:相关问题 更多 >
编程相关推荐