From be2442e22230475c6a4e302879cd3eb5be318e2e Mon Sep 17 00:00:00 2001 From: hugogogo Date: Sun, 26 Oct 2025 17:24:58 +0100 Subject: [PATCH] ex04 ok --- d00/ex04/whatis.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 d00/ex04/whatis.py diff --git a/d00/ex04/whatis.py b/d00/ex04/whatis.py new file mode 100644 index 0000000..ffb6ac5 --- /dev/null +++ b/d00/ex04/whatis.py @@ -0,0 +1,24 @@ +def check_parity(args: list[str]): + if len(args) == 0: + return + if len(args) > 1: + print("AssertionError: more than one argument is provided") + return + + arg = args[0] + try: + number = int(arg) + except ValueError: + print("AssertionError: argument is not an integer") + return + + if number % 2 == 0: + print("I'm Even.") + else: + print("I'm Odd.") + +# execute module as a script : https://docs.python.org/3.10/tutorial/modules.html#executing-modules-as-scripts +if __name__ == "__main__": + # https://docs.python.org/3.10/library/sys.html + import sys + check_parity(sys.argv[1:]) \ No newline at end of file