Same output as solution but can't pass

:slight_smile: i,

My code for the #2 problem of " Distance Between Points - 3D" is different from Codecademy’s (as provided by “View Solution”). But mine couldn’t pass.
Not sure what’s the issue…

Code link for both mine and Codecademy’s: Distance-Between-Points---3D/Distance Between Points - 3D-Copy1.ipynb at 457b529ab8f5889d2520aaacf1738305a416110d · youshanchung/Distance-Between-Points---3D · GitHub

Thanks a lot!:slight_smile:

YS

You haven’t linked to the exercise. Is it specified in the instructions that the numbers in the lists are expected to be integers only? If the lists can have decimal numbers, then your code will give a different output than the Codecademy solution code. e.g.

star_wars = [125.25, 1977, 11000000]
raiders = [115.56, 1981, 18000000]
mean_girls = [97.89, 2004, 17000000]

will give different output for the two codes.

Also, your function’s name is distance, but you have also used another variable with the name distance within the function. That isn’t a good idea.

Hi ,

Thanks for reminding. Here’s the exercise link:https://www.codecademy.com/paths/data-science-nlp/tracks/mle-supervised-learning-i/modules/mle-k-nearest-neighbors/lessons/knn/exercises/distance-three-d

It didn’t say the numbers have to be integers. My code printed floats, and so did Codecademy’s.

I’ve also renamed one of the “distances”.

Solved. I reported it as a bug and passed the code verification. Thanks a lot! :smiley:

# Your code:
(int(movie1[i])-int(movie2[i]))**2

# Solution code:
(movie1[i] - movie2[i]) ** 2

If the numbers in the lists are floats, your code will produce a different output than the solution code (because you are converting the floats to ints before finding the difference between them).

a = [31.56, 54.19, 99.88]
b = [12.63, 98.54, 73.05]

# Solution code
print(distance(a,b))
# 55.182572430070714

# Your code
print(distance(a,b))
# 54.5252235208623

Yeah. I think my output was the same as Codecademy’s because the features happen to be integers. So it makes no difference with or without the int() function or not.

The features of this exercise:

star_wars = [125, 1977, 11000000]
raiders = [115, 1981, 18000000]
mean_girls = [97, 2004, 17000000]