1
0
forked from tdwojak/Python2017
Python2017/labs02/task05.py

31 lines
823 B
Python
Raw Permalink Normal View History

2017-11-18 16:45:28 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Napisz funkcję euclidean_distance obliczającą odległość między
dwoma punktami przestrzeni trójwymiarowej. Punkty dane jako
trzyelementowe listy liczb zmiennoprzecinkowych.
2017-11-19 10:42:39 +01:00
np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5.
2017-11-18 16:45:28 +01:00
"""
def euclidean_distance(x, y):
if len(x) != len(y):
return 0
else:
return ((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2) ** (1 / 2)
2017-11-18 16:45:28 +01:00
def tests(f):
inputs = [[(2.3, 4.3, -7.5), (2.3, 8.5, -7.5)]]
outputs = [4.2]
for input, output in zip(inputs, outputs):
if f(*input) != output:
return "ERROR: {}!={}".format(f(*input), output)
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(euclidean_distance))