{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Workbook for Chapter 2 of Explorations in Computing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Section 2.4: Defining New Functions: Statements"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T31. Enter the definition of the `celsius` function from Figure 2.5 in the code cell below.\n",
"\n",
"**Important** Type the code exactly as it is shown in the textbook, including the four spaces before the word `return`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"T32. After you have entered the complete definition in the cell above tell Python to execute the cell by typing ⌃⏎ \n",
"\n",
"If Python does not print anything after you evaluate the cell you are ready to test the function. If the output area below the code cell shows any error messages fix the mistake and type ⌃⏎ again. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T33. Evaluate expressions that call your new function:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T34. If you did not include the docstring in your code cell add it now and type ⌃⏎ again."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T35. Now that your function has a docstring Python should print a helpful message when you ask to see its documentation. Type `help(celsius)` in the cell below and hit ⌃⏎"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T36. Enter the definition of the `countertop` function from Figure 2.6 in this code cell and then execute the cell by typing ⌃⏎"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T38. Evaluate some expressions that test the new function:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T39. To verify the fact that `square` is a local variable try to evaluate an expression that uses `square`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T40. What would Python have printed for the value of `2 * square` if `square` was not a local variable, that is, if the value was still available after returning from the call to `countertop`? Enter your answer in the markdown cell below."
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"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.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}