# Code for Monte Carlo class, Jonathan Goodman # http://www.math.nyu.edu/faculty/goodman/teaching/MonteCarlo20/ # DatumClassDef.py # The author gives permission for anyone to use this publicly posted # code for any purpose. The code was written for teaching, not research # or commercial use. It has not been tested thoroughly and probably has # serious bugs. Results may be inaccurate, incorrect, or just wrong. # The tow modules are used for the Week 2 classes. # See the special notes on Python 3 classes for Week 2. # DatumCaller.py # DatumClassDef.py class datum: """A class to represent a floating point number associated to a name. A 'datum' (from a Latin word for 'given') is one numerical piece of information that one would use in statistics. More than one datum is `data'. One datum, two data. """ def __init__(self, val = 0., name = "blank"): """Create a datum with given value and name record the given value and name""" self.val = float(val) # Cast the given value to float self.name = name def get_val(self): """return the value""" return self.val # Don't need comments for obvious things def get_name( self): """return the name""" return self.name def double_val( self): "double the value" self.val = 2.*self.val def cap( self, x): """cap x by not letting it be larger than the data value Return the minimum of x and the value.""" if (self.val < x): # the data value if x is larger return self.val return x def add_val( self, increment): """add the increment to the value and store the new value""" self.val = self.val + float(increment)