{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "from ipythonblocks import BlockGrid" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "grid = BlockGrid(10, 10, fill=(123, 234, 123))\n", "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "WHITE = (255, 255, 255)\n", "RED = (255, 0, 0)\n", "GREEN = (0, 255, 0)\n", "BLUE = (0, 0, 255)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 1\n", "\n", "Modify the next cell to contain two for loops. The first for loop should set the last row to red. The second for loop should set the last column to white." ] }, { "cell_type": "code", "collapsed": false, "input": [ "grid = BlockGrid(10, 10, fill=(123, 234, 123))\n", "\n", "# put for loops here\n", "\n", "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 4, "text": [ "" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 2\n", "\n", "Write a for loop so that every other cell along the diagonal is white. Your final grid should look like the following, BUT with using a for loop instead.\n", "\n", "Hint: you want to color on an even set of numbers. You can either multiple i by 2 (i`*`2) or write an 'if' statement to test if i % 2 == 0." ] }, { "cell_type": "code", "collapsed": false, "input": [ "grid = BlockGrid(10, 10, fill=(123, 234, 123))\n", "grid[0, 0] = WHITE\n", "grid[2, 2] = WHITE\n", "grid[4, 4] = WHITE\n", "grid[6, 6] = WHITE\n", "grid[8, 8] = WHITE\n", "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 5, "text": [ "" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "grid = BlockGrid(10, 10, fill=(123, 234, 123))\n", "# put for loop here\n", "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 6, "text": [ "" ] } ], "prompt_number": 6 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem 3\n", "\n", "Write a nested for loop so that you color each row progressively more red, starting at black. (See definition of RED above.) Your final grid should look like the below, but with rows getting redder instead of columns." ] }, { "cell_type": "code", "collapsed": false, "input": [ "grid = BlockGrid(10, 10, fill=(123, 234, 123))\n", "grid[:,0] = (0, 0, 0)\n", "grid[:,1] = (10, 0, 0)\n", "grid[:,2] = (20, 0, 0)\n", "grid[:,3] = (30, 0, 0)\n", "grid[:,4] = (40, 0, 0)\n", "grid[:,5] = (50, 0, 0)\n", "grid[:,6] = (60, 0, 0)\n", "grid[:,7] = (70, 0, 0)\n", "grid[:,8] = (80, 0, 0)\n", "grid[:,9] = (90, 0, 0)\n", "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 7, "text": [ "" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "grid = BlockGrid(10, 10, fill=(123, 234, 123))\n", "# put for loop here\n", "grid" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 8, "text": [ "" ] } ], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 } ], "metadata": {} } ] }