-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcircle.py
More file actions
32 lines (23 loc) · 727 Bytes
/
circle.py
File metadata and controls
32 lines (23 loc) · 727 Bytes
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
#!/usr/bin/env python
"""
circle class -- my solution to the exercise
test code to run it is in test_circle.py
"""
import math
class Circle(object):
def __init__(self, radius):
self.radius = radius
def get_diameter(self):
return self.radius * 2
def set_diameter(self, value):
self.radius = value / 2.0
diameter = property(get_diameter, set_diameter)
def get_area(self):
return self.radius**2 * math.pi
area = property(get_area)
def __add__(self, other):
return Circle(self.radius + other.radius)
def __repr__(self):
return "Circle(%f)"%self.radius
def __str__(self):
return "Circle Object with radius: %f"%self.radius