Solution 1

# Import the library here!
import math

def area_of_circle(radius):
    return math.pi * radius * radius

Area of Circle

Time for the math library. It has a lot of mathematical methods and numbers. Surprised?

Suppose you wanted to calculate the area of a circle with more precision and you didn't have pi memorized to 100 digits like most people do. You could either start learning about pi... or just use the math library!

Okay... time to make that hypothetical area of a circle program less hypothetical.

Create a function area_of_circle that receives the radius and returns the area of the circle (pi * r * r) using the math library to get your value for pi.


area_of_circle(1) #  3.141592653589793

area_of_circle(2) # 12.566370614359172

Test Cases

test area radius three - Run Test

def test_area_radius_three():
    assert area_of_circle(3) == 28.274333882308138

test area radius one - Run Test

def test_area_radius_one():
    assert area_of_circle(1) == 3.141592653589793
# Import the library here! def area_of_circle(radius): pass