擅长:python、mysql、java
<pre><code>def difference(numbers):
dif_list=[]
i = 0
while i < len(numbers)-1:
dif_list.append(numbers[i+1]-numbers[i])
i +=1
if len(dif_list) == len(numbers)-1:
return dif_list
assert difference([1,2,5,3]) == [1, 3, -2]
print('pass')
</code></pre>
<p>输出:<code>pass</code></p>
<p>主要的问题是您返回了一个print(),但我也将您的dif_列表移到了for循环之外,因为这很有意义。变化不大,但这就是我要说的。我可能也会对它进行一些重构,但它现在已经运行了</p>
<p>编辑-我忍不住要重构一点,因为你的<code>for</code>循环完全没有必要,它什么都没做</p>