Practice Problems¶

Lecture 5¶

Answer each number in a separate cell

Rename the notebook with your lastName and the lecture

ex. CychB_05



Turn this notebook into TritonEd by the end of class

1. Doc string
• Create a function greeting( ). Include a doc string that explains what the function does
• In the body, use the command print ('Hi there')
• print out the docstring with help(greeting)
2. Functions
• create a function called circleArea( ) . The function should take a radius as an argument and return the area of a circle with that radius ($A=\pi r^2$). Include a doc string (as ALWAYS).
• call the function and print out the result
• Create a function called add_em_up( ) that takes an unspecified number of input floating point or integer arguments and returns their sum.
• Call the function with different numbers of arguments and print the sum.
3. Modules
• Create a module myMath.py in a separate text file
• Add the functions add_em_up(*args) and circleArea(r) to the module myMath.py but rename them add and area
• save the module using the %%writefile magic command.
• import the myMath.py module into your Jupyter notebook and call each function in the module
4. Local variables
• define a variable myName with your name
• define a function greeting( ) that sets myName to "John Doe". The function should return the string "Hello" and the variable myName
• print myName
• call the function greeting( ) and print the output
• print myName again
• Has the value of myName changed after calling the function greeting( )?
5. Global variables
• define a variable name with your name
• define a function greet( ) that sets the global variable name to "Jane Doe". The function should return "Hello" and the variable name
• print name
• call the function greet( ) and print the output
• print name
• Has the value of name changed after calling the function greet( )?
In [ ]: