#!/usr/bin/env python # -*- coding: utf-8 -*- """ 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. """ import cmath def euclidean_distance(x, y): odleglosc=0 for i in range(3): odleglosc= odleglosc + (x[i] - y[i]) ** 2 odleglosc = cmath.sqrt(odleglosc) #odleglosc=odleglosc ** (1/2) return odleglosc 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))