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