################################################################### # This file is unit01_SampleFunctions.py. It contains a few sample functions # written in Python, included for pedagogical purposes. # George Gollin, University of Illinois, April 29, 2016 ################################################################### def SampleFunction1(x, y, z): """ This function returns (x * y) + z. Created on Thu Apr 28 16:34:11 2016 Note that the multi-line string literal (all the stuff between the triple quotes) serves as a "docstring": it is printed in response to a help query about this function. Use SampleFunction1 this way: import SampleFunctions # load the module help(SampleFunctions.SampleFunction1) # ask for help TheAnswer = SampleFunctions.SampleFunction1(3,4,5) # call the function @author: g-gollin """ WorkingVariable = x * y WorkingVariable = WorkingVariable + z return WorkingVariable # end of SampleFunction1 ################################################################### # Now define a second function ################################################################### def SampleFunction2(x, y): """ This function returns sqrt(x^2 + y^2). Use this way after importing the module: print(SampleFunctions.SampleFunction2(3,4)) """ # sum the squares of the two arguments WorkingVariable = x**2 + y**2 # ^ doesn't work for exponentiation. # now take the square root WorkingVariable = WorkingVariable ** 0.5 # all done. return WorkingVariable # end of SampleFunction2 ###################################################################