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: https://github.com/youshanchung/Distance-Between-Points---3D/blob/457b529ab8f5889d2520aaacf1738305a416110d/Distance%20Between%20Points%20-%203D-Copy1.ipynb
Thanks a lot!
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.
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!
# Your code:
# 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
# Your code
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]