#!/usr/bin/env python # -*- coding: utf-8 -*- import math as mt """ Napisz funkcję euclidean_distance obliczającą odległość między dwoma punktami przestrzeni trójwymiarowej. Punkty są dane jako trzyelementowe listy liczb zmiennoprzecinkowych. np. odległość pomiędzy punktami (0, 0, 0) i (3, 4, 0) jest równa 5. """ def euclidean_distance(x, y): x1 = x[0] y1 = x[1] z1 = x[2] x2 = y[0] y2 = y[1] z2 = y[2] return mt.sqrt((x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2) 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))