diff --git a/division/__init__.py b/division/__init__.py new file mode 100644 index 0000000..6dc7ae6 --- /dev/null +++ b/division/__init__.py @@ -0,0 +1 @@ +# don't modify this file diff --git a/division/main.py b/division/main.py new file mode 100644 index 0000000..6a66a70 --- /dev/null +++ b/division/main.py @@ -0,0 +1,23 @@ +# ANSI color codes +blue = "\033[34m" # Blue +red = "\033[31m" # Red +green = "\033[32m" # Green +reset = "\033[0m" # Reset to default color + +def divide(x: int, y: int) -> float | None: + try: + x = int(x) + y = int(y) + except ValueError: + return print(f"{red}You cannot divide by strings!{reset}") + + if y == 0: + return print(f"{red}You cannot divide by 0!{reset}") + return float(x/y) + +if __name__ == "__main__": + x = input(f"{blue}Input a number to divide:{reset} ") + y = input(f"{blue}Input a number to divide by:{reset} ") + result = divide(x,y) + if result is not None: + print(f"{green}{result}{reset}") \ No newline at end of file