python
python
The problem requires calculating the length of a right triangle's hypotenuse given two legs' lengths.
We'll define a function `hypotenuse(a, b)`.
import math
return c
Stage 3: Testing
# Test 1: hypotenuse(3, 4)
print(hypotenuse(3, 4)) # Output: 5.0
def circle_area(radius):
# Validate input
if radius < 0:
raise ValueError("Radius cannot be negative")
# Calculate area
area = math.pi * (radius ** 2)
return area
Stage 3: Testing
# Test 1: circle_area(5)
print(circle_area(5)) # Output: 78.53981633974483
# Test 2: circle_area(10)
print(circle_area(10)) # Output: 314.1592653589793
# Test 3: circle_area(15)
print(circle_area(15)) # Output: 707.1067811865476
References:
1. Downey, A. (2015). Think Python: How to think like a computer scientist. Needham,
Massachusetts: Green Tree Press.
( https://greenteapress.com/thinkpython2/thinkpython2.pdf )