|
60 | 60 | },
|
61 | 61 | {
|
62 | 62 | "cell_type": "code",
|
63 |
| - "execution_count": 1, |
| 63 | + "execution_count": 14, |
64 | 64 | "metadata": {},
|
65 | 65 | "outputs": [
|
66 | 66 | {
|
67 | 67 | "name": "stdout",
|
68 | 68 | "output_type": "stream",
|
69 | 69 | "text": [
|
70 |
| - "zsh:1: no matches found: scripts/hello-world*.py\r\n" |
| 70 | + "scripts/hello-world-in-swedish.py scripts/hello-world.py\r\n" |
71 | 71 | ]
|
72 | 72 | }
|
73 | 73 | ],
|
|
77 | 77 | },
|
78 | 78 | {
|
79 | 79 | "cell_type": "code",
|
80 |
| - "execution_count": 2, |
| 80 | + "execution_count": 15, |
81 | 81 | "metadata": {},
|
82 | 82 | "outputs": [
|
83 | 83 | {
|
84 | 84 | "name": "stdout",
|
85 | 85 | "output_type": "stream",
|
86 | 86 | "text": [
|
87 |
| - "cat: scripts/hello-world.py: No such file or directory\r\n" |
| 87 | + "#!/usr/bin/env python\r\n", |
| 88 | + "\r\n", |
| 89 | + "print(\"Hello world!\")\r\n" |
88 | 90 | ]
|
89 | 91 | }
|
90 | 92 | ],
|
|
94 | 96 | },
|
95 | 97 | {
|
96 | 98 | "cell_type": "code",
|
97 |
| - "execution_count": 3, |
| 99 | + "execution_count": 16, |
98 | 100 | "metadata": {},
|
99 | 101 | "outputs": [
|
100 | 102 | {
|
101 | 103 | "name": "stdout",
|
102 | 104 | "output_type": "stream",
|
103 | 105 | "text": [
|
104 |
| - "python: can't open file 'scripts/hello-world.py': [Errno 2] No such file or directory\r\n" |
| 106 | + "Hello world!\r\n" |
105 | 107 | ]
|
106 | 108 | }
|
107 | 109 | ],
|
|
129 | 131 | },
|
130 | 132 | {
|
131 | 133 | "cell_type": "code",
|
132 |
| - "execution_count": 4, |
| 134 | + "execution_count": 17, |
133 | 135 | "metadata": {},
|
134 | 136 | "outputs": [
|
135 | 137 | {
|
136 | 138 | "name": "stdout",
|
137 | 139 | "output_type": "stream",
|
138 | 140 | "text": [
|
139 |
| - "cat: scripts/hello-world-in-swedish.py: No such file or directory\r\n" |
| 141 | + "#!/usr/bin/env python\r\n", |
| 142 | + "# -*- coding: UTF-8 -*-\r\n", |
| 143 | + "\r\n", |
| 144 | + "print(\"Hej världen!\")\r\n" |
140 | 145 | ]
|
141 | 146 | }
|
142 | 147 | ],
|
|
146 | 151 | },
|
147 | 152 | {
|
148 | 153 | "cell_type": "code",
|
149 |
| - "execution_count": 5, |
| 154 | + "execution_count": 18, |
150 | 155 | "metadata": {},
|
151 | 156 | "outputs": [
|
152 | 157 | {
|
153 | 158 | "name": "stdout",
|
154 | 159 | "output_type": "stream",
|
155 | 160 | "text": [
|
156 |
| - "python: can't open file 'scripts/hello-world-in-swedish.py': [Errno 2] No such file or directory\r\n" |
| 161 | + "Hej världen!\r\n" |
157 | 162 | ]
|
158 | 163 | }
|
159 | 164 | ],
|
|
3573 | 3578 | "* http://www.greenteapress.com/thinkpython/ - A free book on Python programming.\n",
|
3574 | 3579 | "* [Python Essential Reference](http://www.amazon.com/Python-Essential-Reference-4th-Edition/dp/0672329786) - A good reference book on Python programming."
|
3575 | 3580 | ]
|
| 3581 | + }, |
| 3582 | + { |
| 3583 | + "cell_type": "markdown", |
| 3584 | + "metadata": {}, |
| 3585 | + "source": [ |
| 3586 | + "## Exercise 1" |
| 3587 | + ] |
| 3588 | + }, |
| 3589 | + { |
| 3590 | + "cell_type": "markdown", |
| 3591 | + "metadata": {}, |
| 3592 | + "source": [ |
| 3593 | + "<div class=\"alert alert-success\">\n", |
| 3594 | + "Implement the function <code>print_routine</code> that iterates over the `days_of_the_week` list and prints the routine in following format:\n", |
| 3595 | + "<pre>\n", |
| 3596 | + "Today is Sunday\n", |
| 3597 | + " Sleep in\n", |
| 3598 | + "Today is Monday\n", |
| 3599 | + " Go to work\n", |
| 3600 | + "Today is Tuesday\n", |
| 3601 | + " Go to work\n", |
| 3602 | + "Today is Wednesday\n", |
| 3603 | + " Go to work\n", |
| 3604 | + "Today is Thursday\n", |
| 3605 | + " Go to work\n", |
| 3606 | + "Today is Friday\n", |
| 3607 | + " Go to work\n", |
| 3608 | + "Today is Saturday\n", |
| 3609 | + " Do chores\n", |
| 3610 | + "</pre>\n", |
| 3611 | + "</div>" |
| 3612 | + ] |
| 3613 | + }, |
| 3614 | + { |
| 3615 | + "cell_type": "code", |
| 3616 | + "execution_count": null, |
| 3617 | + "metadata": {}, |
| 3618 | + "outputs": [], |
| 3619 | + "source": [ |
| 3620 | + "days_of_the_week = [\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]\n", |
| 3621 | + "\n", |
| 3622 | + "def print_routine():\n", |
| 3623 | + " \"\"\"Print\n", |
| 3624 | + " \n", |
| 3625 | + " \"\"\"\n", |
| 3626 | + " ### BEGIN SOLUTION\n", |
| 3627 | + " raise NotImplementedError()\n", |
| 3628 | + " ### END SOLUTION" |
| 3629 | + ] |
| 3630 | + }, |
| 3631 | + { |
| 3632 | + "cell_type": "code", |
| 3633 | + "execution_count": null, |
| 3634 | + "metadata": {}, |
| 3635 | + "outputs": [], |
| 3636 | + "source": [ |
| 3637 | + "print_routine()" |
| 3638 | + ] |
| 3639 | + }, |
| 3640 | + { |
| 3641 | + "cell_type": "markdown", |
| 3642 | + "metadata": {}, |
| 3643 | + "source": [ |
| 3644 | + "---\n", |
| 3645 | + "## Excercise: Fibonacci Sequence\n", |
| 3646 | + "\n", |
| 3647 | + "The Fibonacci sequence is a sequence in math that starts with 0 and 1, and then each successive entry is the sum of the previous two. Thus, the sequence goes *0,1,1,2,3,5,8,13,21,34,55,89,...*\n", |
| 3648 | + "\n", |
| 3649 | + "A very common exercise in programming books is to compute the Fibonacci sequence up to some number *n*." |
| 3650 | + ] |
| 3651 | + }, |
| 3652 | + { |
| 3653 | + "cell_type": "markdown", |
| 3654 | + "metadata": {}, |
| 3655 | + "source": [ |
| 3656 | + "<div class=\"alert alert-success\">\n", |
| 3657 | + "Implement the function <code>fibonacci</code> Return the Fibonacci sequence of length *sequence_length*\n", |
| 3658 | + "</div>" |
| 3659 | + ] |
| 3660 | + }, |
| 3661 | + { |
| 3662 | + "cell_type": "code", |
| 3663 | + "execution_count": 11, |
| 3664 | + "metadata": {}, |
| 3665 | + "outputs": [], |
| 3666 | + "source": [ |
| 3667 | + "def fibonacci(sequence_length):\n", |
| 3668 | + " \"\"\"Returns the fibonacci sequence for sequence_length\n", |
| 3669 | + " \n", |
| 3670 | + " * If the sequence_length is invalid (<1) raise a ValueError\n", |
| 3671 | + " \n", |
| 3672 | + " Parameters\n", |
| 3673 | + " ----------\n", |
| 3674 | + " sequence_length : number\n", |
| 3675 | + " The length of the fibonacci sequence\n", |
| 3676 | + " \n", |
| 3677 | + " Returns\n", |
| 3678 | + " -------\n", |
| 3679 | + " fibonacci sequence: list\n", |
| 3680 | + " \n", |
| 3681 | + " \"\"\"\n", |
| 3682 | + " ### BEGIN SOLUTION\n", |
| 3683 | + " raise NotImplementedError()\n", |
| 3684 | + " ### END SOLUTION(name):" |
| 3685 | + ] |
| 3686 | + }, |
| 3687 | + { |
| 3688 | + "cell_type": "code", |
| 3689 | + "execution_count": null, |
| 3690 | + "metadata": {}, |
| 3691 | + "outputs": [], |
| 3692 | + "source": [ |
| 3693 | + "from nose.tools import assert_raises\n", |
| 3694 | + "assert_raises(ValueError, fibonacci, 0)\n", |
| 3695 | + "assert fibonacci(2) == [0,1]\n", |
| 3696 | + "assert fibonacci(12) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n", |
| 3697 | + "print(\"success\")" |
| 3698 | + ] |
| 3699 | + }, |
| 3700 | + { |
| 3701 | + "cell_type": "code", |
| 3702 | + "execution_count": null, |
| 3703 | + "metadata": {}, |
| 3704 | + "outputs": [], |
| 3705 | + "source": [] |
3576 | 3706 | }
|
3577 | 3707 | ],
|
3578 | 3708 | "metadata": {
|
|
0 commit comments