擅长:python、mysql、java
<p>你很接近。您要做的是每次通过循环打印<code>abs(x-y)</code>的值。在循环过程中,您可能应该存储这些值的总和,然后在最后打印一次:</p>
<pre><code>Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> UserXRatings = [1,5,1,3.5,4,4,3]
>>> UserYRatings = [5,1,5,1,1,1,1]
>>>
>>> z = 0 # Initialize the variable to store the running total.
>>> for x, y in zip(UserXRatings, UserYRatings):
... z = z + abs(x-y) # Calculate the running total of `abs(x-y)`.
...
>>> print("Manhattan distance: ", z)
Manhattan distance: 22.5
>>>
</code></pre>