Skip to content
Snippets Groups Projects
Commit 87f1c3b4 authored by Vermaat's avatar Vermaat
Browse files

One more exercise

parent 8422a0eb
No related branches found
No related tags found
No related merge requests found
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))
......@@ -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": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment