mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-13 20:56:54 +01:00
27 lines
858 B
Python
27 lines
858 B
Python
import math
|
|
import sys
|
|
|
|
|
|
def print_distance(a: tuple[int, int, int], b: tuple[int, int, int]) -> None:
|
|
distance = math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2)
|
|
print(f"Distance between: {a} and {b}: {distance}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
argv = sys.argv
|
|
try:
|
|
if len(argv) != 2:
|
|
raise Exception("Invalid number of args")
|
|
args = argv[1].split(',')
|
|
if len(args) != 3:
|
|
raise Exception("Invalid argument format." +
|
|
"Try like this : \"15,64,78\"")
|
|
int_args = (int(args[0]), int(args[1]), int(args[2]))
|
|
print("Parsing coordinates:", args[1])
|
|
print_distance((0, 0, 0), int_args)
|
|
except ValueError as err:
|
|
print(f"Parsing invalid coordinates: \"{argv[1]}\"")
|
|
print(err)
|
|
except Exception as err:
|
|
print(err)
|