1
0
Fork 0
Python2017/labs02/task05.py

30 lines
764 B
Python
Raw 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):
2017-11-25 16:31:53 +01:00
dist = 0
for a,b in x,y:
dist = (sum(a-b)**2)**0.5
return dist
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))