← Back to challenges

Make a Circle with OOP

PythonHardobjectsclassesmathgeometry

Instructions

Your task is to create a Circle constructor that creates a circle with a radius provided by an argument. The circles constructed must have two getters getArea() (PI*r^2) and getPerimeter() (2*PI*r) which give both respective areas and perimeter (circumference).

For help with this class, I have provided you with a Rectangle constructor which you can use as a base example.

Examples

circy = Circle(11)
circy.getArea()

# Should return 380.132711084365

circy = Circle(4.44)
circy.getPerimeter()

# Should return 27.897342763877365

Notes

Round results up to the nearest integer.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: One Button Messaging Device