From 58b1a22690821c8be6fe5d4c7ef1b5a7bbeb0e30 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 13 Jun 2012 22:48:09 -0400 Subject: [PATCH] Started a presenter notebook for introductory Python. --- Python/PresenterNotes.ipynb | 671 ++++++++++++++++++++++++++++++++++++ 1 file changed, 671 insertions(+) create mode 100644 Python/PresenterNotes.ipynb diff --git a/Python/PresenterNotes.ipynb b/Python/PresenterNotes.ipynb new file mode 100644 index 0000000..b0425dc --- /dev/null +++ b/Python/PresenterNotes.ipynb @@ -0,0 +1,671 @@ +{ + "metadata": { + "name": "Presenter Notes" + }, + "nbformat": 2, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Math", + "`+ - * / ** %`" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "2 + 5" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 1, + "text": [ + "7" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "2 - 4" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 2, + "text": [ + "-2" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "4 * 5" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 3, + "text": [ + "20" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "6 / 3" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 4, + "text": [ + "2" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "4 ** 2" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 5, + "text": [ + "16" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "4 ** 0.5" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 51, + "text": [ + "2.0" + ] + } + ], + "prompt_number": 51 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "20 % 9" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 10, + "text": [ + "2" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "2 + 3 * 4" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 49, + "text": [ + "14" + ] + } + ], + "prompt_number": 49 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "(2 + 3) * 4" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 50, + "text": [ + "20" + ] + } + ], + "prompt_number": 50 + }, + { + "cell_type": "markdown", + "source": [ + "# Exercise", + "1. Calculate the mean of the numbers 2, 3, and 10.", + "2. Calculate the hypotenuse of a triangle with sides 6 and 8." + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Basic Types", + "`int float string bool`" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "4" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 6, + "text": [ + "4" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "4.0" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 7, + "text": [ + "4.0" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'Hello, Software Carpentry!'" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 9, + "text": [ + "'Hello, Software Carpentry!'" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "True" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 11, + "text": [ + "True" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "False" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 12, + "text": [ + "False" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "markdown", + "source": [ + "# Variables, Print" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = 5", + "b = 2", + "a + b" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 17, + "text": [ + "7" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "c = b", + "b = 95 # changing b doesn't change c", + "a + c" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 18, + "text": [ + "7" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "d = (a + b) * c # doesn't print anything" + ], + "language": "python", + "outputs": [], + "prompt_number": 22 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print a, b, c", + "print d" + ], + "language": "python", + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 95 2", + "200" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "markdown", + "source": [ + "# Containers", + "", + "## Lists" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "l = ['zero', 1, 2.0, '3', 4, 5.0, 'six']" + ], + "language": "python", + "outputs": [], + "prompt_number": 35 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print l[0], l[1]" + ], + "language": "python", + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "zero 1" + ] + } + ], + "prompt_number": 36 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "len(l)" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 37, + "text": [ + "7" + ] + } + ], + "prompt_number": 37 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "l[1:4] # doesn't include end index" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 38, + "text": [ + "[1, 2.0, '3']" + ] + } + ], + "prompt_number": 38 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "l[4:]" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 39, + "text": [ + "[4, 5.0, 'six']" + ] + } + ], + "prompt_number": 39 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "l[:4] # first 4 things" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 40, + "text": [ + "['zero', 1, 2.0, '3']" + ] + } + ], + "prompt_number": 40 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print l[-1], l[-2], l[-2:]" + ], + "language": "python", + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "six 5.0 [5.0, 'six']" + ] + } + ], + "prompt_number": 42 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "l[1] = l[1] + 99", + "l" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 43, + "text": [ + "['zero', 100, 2.0, '3', 4, 5.0, 'six']" + ] + } + ], + "prompt_number": 43 + }, + { + "cell_type": "markdown", + "source": [ + "# Exercise", + "1. Make a list with 5 things in it.", + "2. Print the 4th thing in the list.", + "3. Print the sublist containing the 3rd, 4th, and 5th things in the list." + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Tuples" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "t = ('zero', 1, 2.0)" + ], + "language": "python", + "outputs": [], + "prompt_number": 44 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "t" + ], + "language": "python", + "outputs": [ + { + "output_type": "pyout", + "prompt_number": 45, + "text": [ + "('zero', 1, 2.0)" + ] + } + ], + "prompt_number": 45 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "t[0] = 99" + ], + "language": "python", + "outputs": [ + { + "ename": "TypeError", + "evalue": "'tuple' object does not support item assignment", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/Users/jiffyclub/projects/SWC-bootcamp/Python/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m99\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" + ] + } + ], + "prompt_number": 46 + }, + { + "cell_type": "markdown", + "source": [ + "## Dictionaries" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "d = {'first': 'alpha', 'two': 2, 2: 'two'}", + "print d", + "print d['first'], d[2]" + ], + "language": "python", + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "{2: 'two', 'two': 2, 'first': 'alpha'}", + "alpha two" + ] + } + ], + "prompt_number": 57 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "d['first'] = 'uno'", + "print d['first']" + ], + "language": "python", + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "uno" + ] + } + ], + "prompt_number": 60 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "d['last'] = 'omega'", + "print d['last']", + "d[3.14159] = 'pi'", + "print d[3.14159]" + ], + "language": "python", + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "omega", + "pi" + ] + } + ], + "prompt_number": 61 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print d" + ], + "language": "python", + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "{3.14159: 'pi', 2: 'two', 'last': 'omega', 'two': 2, 'first': 'uno'}" + ] + } + ], + "prompt_number": 62 + }, + { + "cell_type": "markdown", + "source": [ + "# Exercise", + "1. Make a dictionary and experiment using different types as keys. Can containers be keys?" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "outputs": [] + } + ] + } + ] +} \ No newline at end of file -- 2.26.2