{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Workbook for Chapter 4 of Explorations in Computing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Section 4.2: Implementing Linear Search" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Execute this cell to initialize the notebook:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from PythonLabs.IterationLab import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Exercises " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T21. Enter the second definition of `isearch` (the one that uses a `while` loop in Figure 4.2) in the code cell below. After you have entered the complete definition type ⌃⏎ to execute the cell." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T22. Create a list to test `isearch`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T23. Test `isearch` by looking for some strings in the list:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T24. Add the following `print` statement immediately after the `while` statement in your definition of `isearch`. It should be on line 4, and the `if` statement should move down to line 5:\n", "
\n",
"print(’looking in location’, i)\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T25. Type ⌃⏎ in the code cell to update your notebook with the new definition, then repeat the tests in the previous code cells.\n",
"\n",
"Does the function print one line of output for each item it is comparing?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T26. Execute a statement that starts a search that fails:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T27. Ask Python to show you the value of a variable that has not yet been defined in your current shell session:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T28. Save the result of a failed search in `z`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T29. Repeat the statement that asks for the value of `z`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T30. Ask Python to print the type of the object referred to by `z`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"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.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}