From f915ffb79bf0df6285506b88a2bd936fb76682a8 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Sun, 26 Oct 2025 12:38:58 +0100 Subject: [PATCH] ex03 ok --- d00/ex03/NULL_not_found.py | 21 +++++++++++++++++++++ d00/ex03/tester.py | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 d00/ex03/NULL_not_found.py create mode 100644 d00/ex03/tester.py diff --git a/d00/ex03/NULL_not_found.py b/d00/ex03/NULL_not_found.py new file mode 100644 index 0000000..13b1cbd --- /dev/null +++ b/d00/ex03/NULL_not_found.py @@ -0,0 +1,21 @@ +def NULL_not_found(object: any) -> int: + nullType = type(object) + + match object: + case None: + print("Nothing:", object, nullType) + # using a guard https://docs.python.org/3/reference/compound_stmts.html#guards + # (NaN == NaN) = false https://docs.python.org/3.10/reference/expressions.html#value-comparisons "A counter-intuitive implication is that not-a-number values are not equal to themselves" + case float() if object != object: + print("Cheese:", object, nullType) + case bool() if object == False : + print("Fake:", object, nullType) + case int() if object == 0 : + print("Zero:", object, nullType) + case str() if object == '' : + print("Empty:", object, nullType) + case _: + print("Type not Found") + return 1 + + return 0 \ No newline at end of file diff --git a/d00/ex03/tester.py b/d00/ex03/tester.py new file mode 100644 index 0000000..05a3368 --- /dev/null +++ b/d00/ex03/tester.py @@ -0,0 +1,21 @@ +from NULL_not_found import NULL_not_found + +Nothing = None +Garlic = float("NaN") +Garlic2 = float("2") +Zero = 0 +Empty = '' # ’’ +Fake = False +Right = True + +NULL_not_found(Nothing) +NULL_not_found(Garlic) +NULL_not_found(Zero) +NULL_not_found(Empty) +NULL_not_found(Fake) +print(NULL_not_found("Brian")) + +print("--") +NULL_not_found(Garlic2) +NULL_not_found(Right) +print(NULL_not_found("")) \ No newline at end of file