1
1
Fork 0
PythonLearning/division/main.py

23 lines
662 B
Python
Raw Normal View History

# 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}")