1
1
Fork 0
PythonLearning/hypotenuse/main.py

22 lines
628 B
Python
Raw Normal View History

2024-05-08 10:41:01 -04:00
from math import sqrt
2024-05-08 12:18:03 -04:00
# ANSI color codes
BLUE = "\033[34m" # Blue
RED = "\033[31m" # Red
GREEN = "\033[32m" # Green
RESET = "\033[0m" # Reset to default color
2024-05-08 10:41:01 -04:00
def calculate_hypotenuse(x: float, y: float) -> float:
2024-05-08 12:14:29 -04:00
x = float(x)
y = float(y)
return sqrt(x**2 + y**2)
2024-05-08 10:41:01 -04:00
if __name__ == "__main__":
x: str = input(f"{BLUE}Input your A:{RESET} ")
y: str = input(f"{BLUE}Input your B:{RESET} ")
2024-05-08 12:14:29 -04:00
try:
result: float = calculate_hypotenuse(float(x), float(y))
2024-05-08 12:18:03 -04:00
print(f"{GREEN}{round(result)} ({result}){RESET}")
2024-05-08 12:14:29 -04:00
except ValueError:
2024-05-08 12:18:03 -04:00
print(f"{RED}Please do not input strings.{RESET}")