Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' Circuitous, LLC -
- An Advanced Circle Analytic Company
- '''
- import math
- class Circle(object):
- 'An advanced circle analytic toolkit'
- version = '0.1' # class variable
- def __init__(self, radius):
- self.radius = radius # instance variable
- def angle_to_grade(self, angle):
- 'Convert angle in degree to a percentage grade'
- return math.tan(math.radians(angle)) * 100.0
- def area(self):
- 'Perform quadrature on a shape of uniform radius'
- # incorrect way
- #return 3.14 * self.radius ** 2.0
- # correct way - use import math
- return math.pi * self.radius ** 2.0
- # modules for code reuse
- @classmethod # alternative constructor
- def from_bbd(cls, bbd):
- 'Construct a circle from a bounding box diagonal'
- radius = bbd / 2.0 / math.sqrt(2.0)
- #wrong- return Circle(radius)
- return cls(radius)
- # Regular methods have "self" as first argument.
- # Tutorial
- print 'Circuitous version', Circle.version
- c = Circle(10)
- print 'A circle of radius', c.radius
- print 'has an area of', c.area()
- print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement