Calculating the Hypotenuse of a Right Triangle

Write a Python program that uses the math module to find the hypotenuse of a right triangle given the lengths of the other two sides.

Example 1:

Input: 3, 4
Output: 5.0

Example 2:

Input: 5, 12
Output: 13.0

The math module contains a function hypot(x, y) that calculates the hypotenuse of a right triangle given the lengths of the other two sides.

import math

# Define the function
def calculate_hypotenuse(a, b):
    return math.hypot(a, b)

# Test the function
print(calculate_hypotenuse(3, 4))  # Output: 5.0
print(calculate_hypotenuse(5, 12))  # Output: 13.0

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!