# Code for Monte Carlo class, Jonathan Goodman # http://www.math.nyu.edu/faculty/goodman/teaching/MonteCarlo20/ # DatumCaller.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 import DatumClassDef as dat x = dat.datum(3,"x value") print("The new class instance x has type " + str(type(x))) print("x has value: " + str(x.get_val())) print("x has name: " + str(x.get_name())) x.double_val() print("after doubling, x has value: " + str(x.get_val())) x.add_val(-2) print("after incrementing, x has value: " + str(x.get_val())) y = dat.datum("33.2") print("y has value: " + str(y.get_val())) print("y has name: " + str(y.get_name())) y = x print("after rebinding, y has value: " + str(y.get_val())) print("after rebinding, y has name: " + str(y.get_name())) y.double_val() print("after doubling y value, the x value is " + str(x.get_val())) z1 = 7 z2 = 9 print("capping " + str(z1) + " gives " + str(x.cap(z1))) print("capping " + str(z2) + " gives " + str(x.cap(z2)))