From 87f1c3b4533259cba8c5d4334288c1aa5e0e2130 Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Sun, 4 Aug 2013 23:24:23 +0200 Subject: [PATCH] One more exercise --- fibonacci.py | 10 ---------- python.ipynb | 56 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 30 deletions(-) delete mode 100644 fibonacci.py diff --git a/fibonacci.py b/fibonacci.py deleted file mode 100644 index 75da24c..0000000 --- a/fibonacci.py +++ /dev/null @@ -1,10 +0,0 @@ -def fib(n): - if n == 0: - return 0 - if n == 1: - return 1 - return fib(n - 1) + fib(n - 2) - -if __name__ == '__main__': - for n in range(5, 10): - print 'fib({0}) = {1}'.format(n, fib(n)) diff --git a/python.ipynb b/python.ipynb index 36836bb..3d35e73 100644 --- a/python.ipynb +++ b/python.ipynb @@ -784,7 +784,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "type('an example string')" + "type('I am a homo sapiens')" ], "language": "python", "metadata": {}, @@ -792,13 +792,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 21, + "prompt_number": 11, "text": [ "str" ] } ], - "prompt_number": 21 + "prompt_number": 11 }, { "cell_type": "markdown", @@ -818,7 +818,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "'abc' * 5 + 'def'" + "'beer' * 5 + 'whiskey'" ], "language": "python", "metadata": {}, @@ -826,13 +826,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 22, + "prompt_number": 12, "text": [ - "'abcabcabcabcabcdef'" + "'beerbeerbeerbeerbeerwhiskey'" ] } ], - "prompt_number": 22 + "prompt_number": 12 }, { "cell_type": "markdown", @@ -845,7 +845,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "a = 'abc'\n", + "a = 'spezi'\n", "type(a)" ], "language": "python", @@ -854,13 +854,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 23, + "prompt_number": 13, "text": [ "str" ] } ], - "prompt_number": 23 + "prompt_number": 13 }, { "cell_type": "markdown", @@ -873,7 +873,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "'abc' + 34" + "'beer' + 34" ], "language": "python", "metadata": {}, @@ -884,12 +884,12 @@ "output_type": "pyerr", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m<ipython-input-24-43a6c1044bb0>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;34m'abc'\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m34\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m<ipython-input-14-ec918fbfdf41>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;34m'beer'\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m34\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mTypeError\u001b[0m: cannot concatenate 'str' and 'int' objects" ] } ], - "prompt_number": 24 + "prompt_number": 14 }, { "cell_type": "markdown", @@ -1368,7 +1368,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "len('abcdefghijkl')" + "len('attacgataggcatccgt')" ], "language": "python", "metadata": {}, @@ -1376,13 +1376,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 39, + "prompt_number": 15, "text": [ - "12" + "18" ] } ], - "prompt_number": 39 + "prompt_number": 15 }, { "cell_type": "code", @@ -1408,7 +1408,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "('abc', 22, True, 'abc').count('abc')" + "('atg', 22, True, 'atg').count('atg')" ], "language": "python", "metadata": {}, @@ -1416,13 +1416,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 41, + "prompt_number": 16, "text": [ "2" ] } ], - "prompt_number": 41 + "prompt_number": 16 }, { "cell_type": "markdown", @@ -3530,6 +3530,22 @@ " b = a" ] }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "$\\S$ Exercise: Running code from a file\n", + "===\n", + "\n", + "* Save your k-mer counting code to a file `kmer_counting.py`.\n", + "* Include some code using it on an example string and printing the results.\n", + "* Run the code from the command line." + ] + }, { "cell_type": "markdown", "metadata": { -- GitLab