擅长:python、mysql、java
<p>当一个函数返回某物时,它会立即中断。所以你的功能就是返回你传递给它的数字。</p>
<p>您需要在打印语句后<code>return abs(n)</code>。</p>
<p>另外,要检查类型,应该使用<a href="http://docs.python.org/2/library/functions.html#isinstance" rel="nofollow">^{<cd2>}</a>。要在这里使用它,您可以执行以下操作:</p>
<pre><code>def distance_from_zero(n):
if isinstance(n, (int, float)):
n = abs(n)
print "The absolute value of the input is ", n
return n
else:
print "Not an integer or float!"
</code></pre>
<hr/>
<p>记住Codecademy检查代码的方式有点“狡猾”。在Codecademy上有一个内置的论坛系统,您可以查看关于某些练习的信息。要通过练习,您可能需要使用<code>type()</code>,而不是像您所做的那样使用<code>isinstance()</code>。</p>