{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Practice Problems\n", "### Lecture 5\n", "Answer each number in a separate cell\n", "\n", "Rename this notebook with your last name and the lecture \n", " \n", " ex. Cych_B_05\n", " \n", "Turn-in this notebook on Canvas." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Doc string\n", " - Create a function **greeting( )**. Include a doc string that explains what the function does\n", " - In the body, use the command **print ('Hi there')**\n", " - print out the docstring with **help(greeting)**\n", "2. Functions\n", " - 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). \n", " - call the function and print out the result\n", " - Create a function called **add_em_up( )** that takes an unspecified number of input floating point or integer arguments and returns their sum.\n", " - Call the function with different numbers of arguments and print the sum.\n", "3. Modules\n", " - Create a module **myMath.py** by copying both functions **add\\_em\\_up(\\*args)** and **circleArea(r)** in a cell\n", " - rename the two functions **add** and **area**\n", " - save the module by using the __%%writefile__ magic command and specifying the file name as **myMath.py**. \n", " - import the **myMath.py** module into your Jupyter notebook and call each function in the module\n", "4. Local variables\n", " - define a variable **myName** with your name\n", " - define a function **greeting( )** that sets myName to \"John Doe\". The function should return the string \"Hello\" and the variable **myName**\n", " - print **myName**\n", " - call the function **greeting( )** and print the output\n", " - print **myName** again \n", " - Has the value of **myName** changed after calling the function **greeting( )**?\n", "5. Global variables\n", " - define a variable **name** with your name\n", " - define a function **greet( )** that sets the global variable **name** to \"Jane Doe\". The function should return \"Hello\" and the variable **name**\n", " - print **name**\n", " - call the function **greet( )** and print the output \n", " - print **name**\n", " - Has the value of **name** changed after calling the function **greet( )**?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }