From 1159d4b189f15008b09675b4dab165dacb0f74c0 Mon Sep 17 00:00:00 2001 From: freezed <2160318-free_zed@users.noreply.gitlab.com> Date: Sun, 18 Apr 2021 00:16:35 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8A=20Log=20when=20input=20are=20ascen?= =?UTF-8?q?ding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit relate to forga/process/fr/embarquement#6 --- tuto-pysdur/pgcd.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tuto-pysdur/pgcd.py b/tuto-pysdur/pgcd.py index 6618b0c..00137bc 100755 --- a/tuto-pysdur/pgcd.py +++ b/tuto-pysdur/pgcd.py @@ -13,6 +13,9 @@ The goal is to build durable python script using standard library This script compute the greater common divisor of 2 integrers """ +# MESSAGES +WRONG_INPUT_ORDER = "Inputs in ascending order" + def pgcd(input_a, input_b): """ @@ -50,6 +53,7 @@ if __name__ == "__main__": # ARGUMENTS, PARAMETERS & OPTIONS import argparse + import logging import sys PARSER = argparse.ArgumentParser( @@ -61,12 +65,21 @@ if __name__ == "__main__": PARSER.add_argument( "-v", "--verbose", help="A near mathematics answer", action="store_true" ) + ARGS = PARSER.parse_args() - # DO THE JOB - NEW_PGCD = pgcd(ARGS.INPUT_A, ARGS.INPUT_B) + # CHECKS INPUTS + if ARGS.INPUT_A <= ARGS.INPUT_B: + logging.critical(WRONG_INPUT_ORDER) + sys.exit() + # DO THE JOB + else: + NEW_PGCD = pgcd(ARGS.INPUT_A, ARGS.INPUT_B) + + # RESPONSE if ARGS.verbose: print(f"PGCD({ARGS.INPUT_A};{ARGS.INPUT_B}) = {NEW_PGCD}") + else: print(NEW_PGCD)