2024-04-29 18:53:35 -05:00
|
|
|
# ANSI color codes
|
2024-04-29 19:00:23 -05:00
|
|
|
BLUE = "\033[34m" # Blue
|
|
|
|
RED = "\033[31m" # Red
|
|
|
|
GREEN = "\033[32m" # Green
|
2024-04-29 19:14:53 -05:00
|
|
|
RESET = "\033[0m" # Reset to default color
|
|
|
|
|
2024-04-29 18:53:35 -05:00
|
|
|
|
2024-04-29 19:00:23 -05:00
|
|
|
def divide(x: float, y: float) -> float | None:
|
2024-04-29 18:53:35 -05:00
|
|
|
try:
|
2024-04-29 19:00:23 -05:00
|
|
|
x = float(x)
|
|
|
|
y = float(y)
|
2024-04-29 18:53:35 -05:00
|
|
|
except ValueError:
|
2024-04-29 19:00:23 -05:00
|
|
|
return print(f"{RED}You cannot divide by strings!{RESET}")
|
2024-04-29 18:53:35 -05:00
|
|
|
|
|
|
|
if y == 0:
|
2024-04-29 19:14:53 -05:00
|
|
|
return print(f"{RED}You cannot divide by 0!{RESET}") # you don't divide by zero
|
|
|
|
return float(x / y)
|
|
|
|
|
2024-04-29 18:53:35 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-04-29 19:00:23 -05:00
|
|
|
x = input(f"{BLUE}Input a number to divide:{RESET} ")
|
|
|
|
y = input(f"{BLUE}Input a number to divide by:{RESET} ")
|
2024-04-29 19:14:53 -05:00
|
|
|
result = divide(x, y)
|
2024-04-29 18:53:35 -05:00
|
|
|
if result is not None:
|
2024-04-29 19:14:53 -05:00
|
|
|
print(f"{GREEN}{result}{RESET}")
|