1
1
Fork 0

math, division
Some checks failed
Actions / Lint Code (Ruff & Pylint) (push) Failing after 12s

This commit is contained in:
EntropicDecay 2024-04-29 19:00:23 -05:00
parent 8c07907b6b
commit b84f62cb59
2 changed files with 14 additions and 13 deletions

View file

@ -4,4 +4,5 @@
missing-module-docstring, missing-module-docstring,
missing-function-docstring, missing-function-docstring,
missing-class-docstring, missing-class-docstring,
line-too-long line-too-long,
redefined-outer-name

View file

@ -1,23 +1,23 @@
# ANSI color codes # ANSI color codes
blue = "\033[34m" # Blue BLUE = "\033[34m" # Blue
red = "\033[31m" # Red RED = "\033[31m" # Red
green = "\033[32m" # Green GREEN = "\033[32m" # Green
reset = "\033[0m" # Reset to default color RESET = "\033[0m" # Reset to default color
def divide(x: int, y: int) -> float | None: def divide(x: float, y: float) -> float | None:
try: try:
x = int(x) x = float(x)
y = int(y) y = float(y)
except ValueError: except ValueError:
return print(f"{red}You cannot divide by strings!{reset}") return print(f"{RED}You cannot divide by strings!{RESET}")
if y == 0: if y == 0:
return print(f"{red}You cannot divide by 0!{reset}") return print(f"{RED}You cannot divide by 0!{RESET}") # you don't divide by zero
return float(x/y) return float(x/y)
if __name__ == "__main__": if __name__ == "__main__":
x = input(f"{blue}Input a number to divide:{reset} ") x = input(f"{BLUE}Input a number to divide:{RESET} ")
y = input(f"{blue}Input a number to divide by:{reset} ") y = input(f"{BLUE}Input a number to divide by:{RESET} ")
result = divide(x,y) result = divide(x,y)
if result is not None: if result is not None:
print(f"{green}{result}{reset}") print(f"{GREEN}{result}{RESET}")