Skip to content

POW WITH ROOTS AND FRACTIONAL EXPONENTS

Python
#!/usr/bin/env python3
"""
POW WITH ROOTS AND FRACTIONAL EXPONENTS
Calculate square roots, cube roots, and nth roots
"""

print("=== Square Roots (power of 0.5) ===")
numbers = [4, 9, 16, 25, 100]

for num in numbers:
    sqrt = pow(num, 0.5)
    print(f"√{num} = {sqrt}")

print("\n=== Cube Roots (power of 1/3) ===")
numbers = [8, 27, 64, 125]

for num in numbers:
    cbrt = pow(num, 1/3)
    print(f"∛{num} = {cbrt:.4f}")

print("\n=== Nth Roots ===")
value = 32
roots = [2, 3, 4, 5]

for n in roots:
    result = pow(value, 1/n)
    print(f"{n}th root of {value} = {result:.4f}")

print("\n=== Distance Formula (uses sqrt) ===")
x1, y1 = 0, 0
x2, y2 = 3, 4

# distance = sqrt((x2-x1)^2 + (y2-y1)^2)
distance = pow(pow(x2-x1, 2) + pow(y2-y1, 2), 0.5)
print(f"Distance from ({x1},{y1}) to ({x2},{y2}) = {distance}")

print("\n=== Area and Volume Relationships ===")
# If area is A, side length is sqrt(A)
area = 64
side = pow(area, 0.5)
print(f"Square with area {area} has side length: {side}")

# If volume is V, side length of cube is cbrt(V)
volume = 125
side = pow(volume, 1/3)
print(f"Cube with volume {volume} has side length: {side:.4f}")

print("\n=== Geometric Mean (uses roots) ===")
# Geometric mean of n numbers = (product)^(1/n)
numbers = [2, 8, 4]
product = 2 * 8 * 4
geometric_mean = pow(product, 1/len(numbers))
print(f"Geometric mean of {numbers} = {geometric_mean:.2f}")