mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-14 05:06:55 +01:00
03/ex5 + flake8
This commit is contained in:
@@ -3,7 +3,9 @@ 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)
|
||||
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}")
|
||||
|
||||
|
||||
@@ -12,15 +14,16 @@ if __name__ == "__main__":
|
||||
try:
|
||||
if len(argv) != 2:
|
||||
raise Exception("Invalid number of args")
|
||||
args = argv[1].split(',')
|
||||
args = argv[1].split(",")
|
||||
if len(args) != 3:
|
||||
raise Exception("Invalid argument format." +
|
||||
"Try like this : \"15,64,78\"")
|
||||
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(f'Parsing invalid coordinates: "{argv[1]}"')
|
||||
print(err)
|
||||
except Exception as err:
|
||||
print(err)
|
||||
|
||||
Reference in New Issue
Block a user