Python Practice › OOP Programs › Program 26
Circle area and circumference
Create a Circle class with a radius and methods for area and circumference.
Output
153.94 43.98
Approach
- Use
math.pi.
Solution
import math class Circle: def __init__(self, radius): self.radius = radius def area(self): return round(math.pi * self.radius ** 2, 2) def circumference(self): return round(2 * math.pi * self.radius, 2) c = Circle(7)print(c.area(), c.circumference())Output
153.94 43.98
Learn the concept
New to this topic? Read the lesson, then come back.