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

32 lines
846 B
Python
Raw Permalink Normal View History

2018-05-12 11:37:19 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2018-05-13 10:04:52 +02:00
import math
2018-05-12 11:37:19 +02:00
"""
Napisz funkcję euclidean_distance obliczającą odległość między
dwoma punktami przestrzeni trójwymiarowej. Punkty 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):
2018-05-13 12:54:21 +02:00
counter = 0
for i in range(len(x)):
d= math.pow(x[i] - y[i],2)
counter += d
distance = math.sqrt(counter)
return distance
2018-05-12 11:37:19 +02: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))