def powers(L):
'''
(list of ints) -> bool
Return True if the given list of ints is a list of powers of some
int x of the form [x^0, x^1, x^2, x^3, ...] and False otherwise.
>>>powers[1, 3, 9, 27, 81]
True
'''
i = 1
x = L[0]
while i < len(L):
if L[i] == x**(i+1):
i += 1
return True
else:
return False
我改变了你指出的错误,但它仍然无法正常工作..你能帮我吗?虽然python上的循环
为什么你使用'+ ='?当你指定new_l [i]'的新值时,你正在使用它;那应该是'='。你在比较时使用它,应该是'=='。另外,在比较值之前,你正在增加'i'。 – Barmar
另一个问题,你分配给'new_l [i]',但是然后你使用'new_L [i]'。 Python区分大小写。 – Barmar
你不需要数组'new_L'。只要测试'L [i] == x ** i'。 – Barmar