Some checks failed
Actions / Lint Code (Ruff & Pylint) (push) Failing after 12s
23 lines
No EOL
698 B
Python
23 lines
No EOL
698 B
Python
# 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: float, y: float) -> float | None:
|
|
try:
|
|
x = float(x)
|
|
y = float(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}") # you don't divide by zero
|
|
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}") |