Advertisement
rfmonk

classDevToolkit.py

Dec 12th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. ''' Circuitous, LLC -
  2.     An Advanced Circle Analytic Company
  3. '''
  4.  
  5. import math
  6.  
  7. class Circle(object):
  8.     'An advanced circle analytic toolkit'
  9.  
  10.  
  11.     version = '0.1'             # class variable
  12.  
  13.     def __init__(self, radius):
  14.         self.radius = radius    # instance variable
  15.  
  16.     def angle_to_grade(self, angle):
  17.         'Convert angle in degree to a percentage grade'
  18.         return math.tan(math.radians(angle)) * 100.0
  19.  
  20.  
  21.     def area(self):
  22.         'Perform quadrature on a shape of uniform radius'
  23.         # incorrect way
  24.         #return 3.14 * self.radius ** 2.0
  25.         # correct way - use import math
  26.         return math.pi * self.radius ** 2.0
  27.         # modules for code reuse
  28.  
  29.     @classmethod                # alternative constructor
  30.     def from_bbd(cls, bbd):
  31.         'Construct a circle from a bounding box diagonal'
  32.         radius = bbd / 2.0 / math.sqrt(2.0)
  33. #wrong- return Circle(radius)
  34.         return cls(radius)
  35.  
  36.  
  37. # Regular methods have "self" as first argument.
  38.  
  39. # Tutorial
  40.  
  41. print 'Circuitous version', Circle.version
  42. c = Circle(10)
  43. print 'A circle of radius', c.radius
  44. print 'has an area of', c.area()
  45. print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement