Skip to content
Snippets Groups Projects
Commit 8ad7bada authored by Vermaat's avatar Vermaat
Browse files

Include calculatory.py and typographic fixes

parent 508b4474
No related branches found
No related tags found
No related merge requests found
{ {
"metadata": { "metadata": {
"name": "" "celltoolbar": "Slideshow",
"name": "",
"signature": "sha256:cc3445be700b04417d5ff13988abf847d17c7d017eea0a2841759469ca16b7fa"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
...@@ -15,63 +17,16 @@ ...@@ -15,63 +17,16 @@
} }
}, },
"source": [ "source": [
"<span style=\"font-size: 200%\">Object Oriented<br /> Programming</span>\n", "<span style=\"font-size: 200%\">Object-oriented programming</span>\n",
"===\n", "===\n",
"\n", "\n",
"<br>\n", "<br>\n",
"\n", "\n",
"[Wibowo Arindrarto](mailto:w.arindrarto@lumc.nl), [Jeroen Laros](mailto:j.f.j.laros@lumc.nl), [Zuotian Tatum](mailto:z.tatum@lumc.nl), [Martijn Vermaat](mailto:m.vermaat.hg@lumc.nl)\n", "[Jeroen Laros](mailto:j.f.j.laros@lumc.nl), [Department of Human Genetics, Leiden University Medical Center](http://humgen.nl)\n",
"\n",
"[Department of Human Genetics, Leiden University Medical Center](http://humgen.nl)\n",
"\n", "\n",
"License: [Creative Commons Attribution 3.0 License (CC-by)](http://creativecommons.org/licenses/by/3.0)" "License: [Creative Commons Attribution 3.0 License (CC-by)](http://creativecommons.org/licenses/by/3.0)"
] ]
}, },
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import HTML, Image, IFrame\n",
"from person import Person\n",
"%pylab inline\n"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"About this notebook\n",
"===\n",
"\n",
"This notebook is the source for a set of slides. If you want to edit them, be sure to choose *Slideshow* in the *Cell Toolbar* menu.\n",
"\n",
"You can use nbconvert to convert the slides to HTML and serve them:\n",
"\n",
" ipython nbconvert --to slides --post serve \"08 - Object-oriented programming.ipynb\" \n",
"\n",
"This will open the slides in a new browser window."
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {
...@@ -120,13 +75,13 @@ ...@@ -120,13 +75,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 3, "prompt_number": 1,
"text": [ "text": [
"('blue', 90, 161)" "('blue', 90, 161)"
] ]
} }
], ],
"prompt_number": 3 "prompt_number": 1
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -147,13 +102,13 @@ ...@@ -147,13 +102,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 4, "prompt_number": 2,
"text": [ "text": [
"90" "90"
] ]
} }
], ],
"prompt_number": 4 "prompt_number": 2
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -194,13 +149,13 @@ ...@@ -194,13 +149,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 5, "prompt_number": 3,
"text": [ "text": [
"['blue', 90, 161]" "['blue', 90, 161]"
] ]
} }
], ],
"prompt_number": 5 "prompt_number": 3
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -221,13 +176,13 @@ ...@@ -221,13 +176,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 6, "prompt_number": 4,
"text": [ "text": [
"161" "161"
] ]
} }
], ],
"prompt_number": 6 "prompt_number": 4
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -268,13 +223,13 @@ ...@@ -268,13 +223,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 7, "prompt_number": 5,
"text": [ "text": [
"{'hair_colour': 'blue', 'length': 161, 'weight': 90}" "{'hair_colour': 'blue', 'length': 161, 'weight': 90}"
] ]
} }
], ],
"prompt_number": 7 "prompt_number": 5
}, },
{ {
"cell_type": "code", "cell_type": "code",
...@@ -288,13 +243,13 @@ ...@@ -288,13 +243,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 8, "prompt_number": 6,
"text": [ "text": [
"90" "90"
] ]
} }
], ],
"prompt_number": 8 "prompt_number": 6
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -325,6 +280,21 @@ ...@@ -325,6 +280,21 @@
" self.length = length" " self.length = length"
] ]
}, },
{
"cell_type": "code",
"collapsed": false,
"input": [
"from person import Person"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"prompt_number": 7
},
{ {
"cell_type": "code", "cell_type": "code",
"collapsed": false, "collapsed": false,
...@@ -339,13 +309,13 @@ ...@@ -339,13 +309,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 9, "prompt_number": 8,
"text": [ "text": [
"90" "90"
] ]
} }
], ],
"prompt_number": 9 "prompt_number": 8
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -383,13 +353,13 @@ ...@@ -383,13 +353,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 10, "prompt_number": 9,
"text": [ "text": [
"90" "90"
] ]
} }
], ],
"prompt_number": 10 "prompt_number": 9
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -435,13 +405,13 @@ ...@@ -435,13 +405,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 11, "prompt_number": 10,
"text": [ "text": [
"(90, 'blue')" "(90, 'blue')"
] ]
} }
], ],
"prompt_number": 11 "prompt_number": 10
}, },
{ {
"cell_type": "code", "cell_type": "code",
...@@ -457,13 +427,13 @@ ...@@ -457,13 +427,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 12, "prompt_number": 11,
"text": [ "text": [
"(93, 'white')" "(93, 'white')"
] ]
} }
], ],
"prompt_number": 12 "prompt_number": 11
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -519,13 +489,13 @@ ...@@ -519,13 +489,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 13, "prompt_number": 12,
"text": [ "text": [
"(205.02965999999998, 93000)" "(205.02965999999998, 93000)"
] ]
} }
], ],
"prompt_number": 13 "prompt_number": 12
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -562,7 +532,7 @@ ...@@ -562,7 +532,7 @@
"source": [ "source": [
"Class variables are defined outside the methods.\n", "Class variables are defined outside the methods.\n",
"\n", "\n",
"* It is still refererenced as **self.** inside the methods." "* It is still refererenced as `self.` inside the methods."
] ]
}, },
{ {
...@@ -593,13 +563,13 @@ ...@@ -593,13 +563,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 14, "prompt_number": 13,
"text": [ "text": [
"80" "80"
] ]
} }
], ],
"prompt_number": 14 "prompt_number": 13
}, },
{ {
"cell_type": "code", "cell_type": "code",
...@@ -614,13 +584,13 @@ ...@@ -614,13 +584,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 15, "prompt_number": 14,
"text": [ "text": [
"79" "79"
] ]
} }
], ],
"prompt_number": 15 "prompt_number": 14
}, },
{ {
"cell_type": "code", "cell_type": "code",
...@@ -637,13 +607,13 @@ ...@@ -637,13 +607,13 @@
{ {
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 16, "prompt_number": 15,
"text": [ "text": [
"90" "90"
] ]
} }
], ],
"prompt_number": 16 "prompt_number": 15
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -661,7 +631,7 @@ ...@@ -661,7 +631,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
" print someone\n", " >>> print someone\n",
" <__main__.Person instance at 0x321ebd8>" " <__main__.Person instance at 0x321ebd8>"
] ]
}, },
...@@ -690,7 +660,7 @@ ...@@ -690,7 +660,7 @@
"source": [ "source": [
"Special methods are prefixed and suffixed with double underscores.\n", "Special methods are prefixed and suffixed with double underscores.\n",
"\n", "\n",
"* There are methods for adding (**\\_\\_add\\_\\_**), subtracting (**\\_\\_sub\\_\\_**), etc." "* There are methods for adding (`__add__`), subtracting (`__sub__`), etc."
] ]
}, },
{ {
...@@ -714,7 +684,7 @@ ...@@ -714,7 +684,7 @@
] ]
} }
], ],
"prompt_number": 17 "prompt_number": 16
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -744,7 +714,7 @@ ...@@ -744,7 +714,7 @@
} }
}, },
"outputs": [], "outputs": [],
"prompt_number": 18 "prompt_number": 17
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -772,7 +742,7 @@ ...@@ -772,7 +742,7 @@
] ]
} }
], ],
"prompt_number": 19 "prompt_number": 18
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
...@@ -830,7 +800,7 @@ ...@@ -830,7 +800,7 @@
"\n", "\n",
"Example (add two numbers):\n", "Example (add two numbers):\n",
"\n", "\n",
" stack.push(stack.pop() + stack.pop())" " >>> stack.push(stack.pop() + stack.pop())"
] ]
}, },
{ {
...@@ -849,7 +819,7 @@ ...@@ -849,7 +819,7 @@
"cell_type": "code", "cell_type": "code",
"collapsed": false, "collapsed": false,
"input": [ "input": [
"%load programming-course-assignments/calculator/calculator.py" "%load examples/calculator.py"
], ],
"language": "python", "language": "python",
"metadata": { "metadata": {
...@@ -858,7 +828,7 @@ ...@@ -858,7 +828,7 @@
} }
}, },
"outputs": [], "outputs": [],
"prompt_number": 40 "prompt_number": 19
}, },
{ {
"cell_type": "code", "cell_type": "code",
...@@ -926,6 +896,7 @@ ...@@ -926,6 +896,7 @@
"cell_type": "code", "cell_type": "code",
"collapsed": false, "collapsed": false,
"input": [ "input": [
"from IPython.display import HTML\n",
"def css_styling():\n", "def css_styling():\n",
" styles = open('styles/custom.css', 'r').read()\n", " styles = open('styles/custom.css', 'r').read()\n",
" return HTML('<style>' + styles + '</style>')\n", " return HTML('<style>' + styles + '</style>')\n",
...@@ -967,13 +938,13 @@ ...@@ -967,13 +938,13 @@
], ],
"metadata": {}, "metadata": {},
"output_type": "pyout", "output_type": "pyout",
"prompt_number": 22, "prompt_number": 21,
"text": [ "text": [
"<IPython.core.display.HTML at 0xb182306c>" "<IPython.core.display.HTML at 0x24109d0>"
] ]
} }
], ],
"prompt_number": 22 "prompt_number": 21
} }
], ],
"metadata": {} "metadata": {}
......
#!/usr/bin/env python
class Stack(list):
def push(self, element):
self.append(element)
def __str__(self):
return str(self[-1])
class Calculator(Stack):
def add(self):
self.push(self.pop() + self.pop())
def sub(self):
temp = self.pop()
self.push(self.pop() - temp)
def mul(self):
self.push(self.pop() * self.pop())
def div(self):
temp = self.pop()
self.push(self.pop() / temp)
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