{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Workbook for Chapter 7 of Explorations in Computing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Section 7.4: Games with Random Numbers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Set Up the Experiments" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The exercises in this notebook use the same `prng` module used in the experiments in the previous section. \n", "\n", "Some of these exercises ask you to change update the file. You can either use a text editor, or, if you want, you can edit the file from your browser. Since `prng.py` is in the same directory as your notebooks, you should see the file alongside all the notebooks when you start IPython. Just click on `prng.py` and IPython will open it in your browser. Now you can edit the file and save your changes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Exercises" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T45. Import the `time` function and call it a few times:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "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": [ "T46. Use `int` in a few expressions to make sure you know what it does:" ] }, { "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": [ "T47. Define a value for `m` and test the expression that uses the system clock to create a seed value:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T48. Edit the assignment statements at the front of your `prng.py` file so they look like the ones in Figure 7.9." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T49. Save your new version of the module and load it into a new interactive session:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T50. Use list comprehension to create a list of ten values from the pseudorandom sequence:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T51. Clear the definitions in the session by selecting Restart from the Kernel menu. In the cells below repeat the commands that import the module and make a list of 10 random values. Did you get a different sequence in this new session?" ] }, { "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": [ "T52. Edit `prng.py` so it includes the function named `roll` shown in Figure 7.8." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "T53. Reload the `prng` module and make a list of 10 rolls:" ] }, { "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 }