0

I fave my functions defined and no error while running the program. The problem is that nothing really happening when I try to call a function.

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')
Ivan Zhugan
  • 21
  • 1
  • 4
  • How do you know nothing happens? Your code has no `print`s so it might do its thing and then terminate.... What is your expected output? – roganjosh Oct 18 '17 at 19:37
  • Also you are returning something but you aren't keeping the value you've returned. – MooingRawr Oct 18 '17 at 19:38

1 Answers1

1

Your function is returning, but you are not doing anything with the returned data. You can assign the return value to a variable x = sim_distance(...) and then do something with that variable. For instance, print(x)