forked from lenafm/calculator_app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle.py
More file actions
36 lines (33 loc) · 1.04 KB
/
circle.py
File metadata and controls
36 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Circle:
"""
A class to represent a circle and perform calculations to it.
Attributes:
radius(float): The radius of the circle
"""
def __init__(self, radius: float):
"""
Constructs the necessary attributes for the circle class.
Parameters:
radius(float): The radius of the circle.
"""
if radius < 0:
raise ValueError("positive radius expected")
self.radius = radius
def area(self) -> float:
"""
Calculates the area of the circle.
Returns:
float: The area of the circle.
"""
assert self.radius >= 0, "positive radius expected"
pi = 3.14159265359
return round(pi * (self.radius ** 2), 2)
def perimeter(self) -> float:
"""
Calculates the perimeter of the circle.
Returns:
float: The perimeter of the circle.
"""
assert self.radius >= 0, "positive radius expected"
pi = 3.14159265359
return round(2 * pi * self.radius, 2)