【发布时间】:2021-05-31 19:18:26
【问题描述】:
我有一个数字列表,其中任何两个相邻数字的总和是一个完美的平方。 列表为 x=[1,8,28,21,4,32,17,19,30,6,3,13,12,24]
for i in range(len(x)-1):
y= x[i]+x[i+1]
z=y**0.5
#till here found the square root of the sum of the adjacent numbers in list
if(z.is_integer==True):
//code
我想检查列表中的剩余数字。如果列表的所有元素都满足条件。然后我想打印列表
预期的输出应该是
[1,8,28,21,4,32,17,19,30,6,3,13,12,24] satisfies the condition
【问题讨论】:
-
你能澄清更多吗?如果你已经找到完美的正方形,那么将 X[i], X[i+1] 追加到新列表中,当 for 循环结束时,打印新列表。
-
is_integer是一个函数,应该是is_integer()。