0
我發揮我的功能定義和運行程序時沒有錯誤。問題是當我嘗試調用一個函數時沒有真正發生。Python - 沒有錯誤,但沒有返回數據無論如何
from math import sqrt
from recommendations import critics
def sim_distance(prefs, p1, p2):
si = {}
for item in prefs[p1]:
if item in prefs[p2]:
si[item] = 1
# If they have no ratings in common, return 0
if len(si) == 0:
return 0
# Add up the squares of all the differences
sum_of_squares = sum([pow(prefs[p1][item] - prefs[p2][item], 2) for item in prefs[p1] if item in prefs[p2]])
return 1/(1 + sqrt(sum_of_squares))
reload (recommendations)
sim_distance(critics, 'Jack Matthews', 'Toby')
你怎麼知道什麼都沒有發生?你的代碼沒有'print',所以它可能會做它的事情,然後終止....你的預期輸出是什麼? – roganjosh
你也回來了一些東西,但你沒有保持你已經返回的價值。 – MooingRawr