Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Programming course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
courses
Programming course
Commits
8ad7bada
Commit
8ad7bada
authored
10 years ago
by
Vermaat
Browse files
Options
Downloads
Patches
Plain Diff
Include calculatory.py and typographic fixes
parent
508b4474
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
08 - Object-oriented programming.ipynb
+61
-90
61 additions, 90 deletions
08 - Object-oriented programming.ipynb
examples/calculator.py
+24
-0
24 additions, 0 deletions
examples/calculator.py
with
85 additions
and
90 deletions
08 - Object-oriented programming.ipynb
+
61
−
90
View file @
8ad7bada
{
"metadata": {
"name": ""
"celltoolbar": "Slideshow",
"name": "",
"signature": "sha256:cc3445be700b04417d5ff13988abf847d17c7d017eea0a2841759469ca16b7fa"
},
"nbformat": 3,
"nbformat_minor": 0,
...
...
@@ -15,63 +17,16 @@
}
},
"source": [
"<span style=\"font-size: 200%\">Object
O
riented
<br /> P
rogramming</span>\n",
"<span style=\"font-size: 200%\">Object
-o
riented
p
rogramming</span>\n",
"===\n",
"\n",
"<br>\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",
"\n",
"[Department of Human Genetics, Leiden University Medical Center](http://humgen.nl)\n",
"[Jeroen Laros](mailto:j.f.j.laros@lumc.nl), [Department of Human Genetics, Leiden University Medical Center](http://humgen.nl)\n",
"\n",
"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",
"metadata": {
...
...
@@ -120,13 +75,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
3
,
"prompt_number":
1
,
"text": [
"('blue', 90, 161)"
]
}
],
"prompt_number":
3
"prompt_number":
1
},
{
"cell_type": "markdown",
...
...
@@ -147,13 +102,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
4
,
"prompt_number":
2
,
"text": [
"90"
]
}
],
"prompt_number":
4
"prompt_number":
2
},
{
"cell_type": "markdown",
...
...
@@ -194,13 +149,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
5
,
"prompt_number":
3
,
"text": [
"['blue', 90, 161]"
]
}
],
"prompt_number":
5
"prompt_number":
3
},
{
"cell_type": "markdown",
...
...
@@ -221,13 +176,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
6
,
"prompt_number":
4
,
"text": [
"161"
]
}
],
"prompt_number":
6
"prompt_number":
4
},
{
"cell_type": "markdown",
...
...
@@ -268,13 +223,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
7
,
"prompt_number":
5
,
"text": [
"{'hair_colour': 'blue', 'length': 161, 'weight': 90}"
]
}
],
"prompt_number":
7
"prompt_number":
5
},
{
"cell_type": "code",
...
...
@@ -288,13 +243,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
8
,
"prompt_number":
6
,
"text": [
"90"
]
}
],
"prompt_number":
8
"prompt_number":
6
},
{
"cell_type": "markdown",
...
...
@@ -325,6 +280,21 @@
" 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",
"collapsed": false,
...
...
@@ -339,13 +309,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
9
,
"prompt_number":
8
,
"text": [
"90"
]
}
],
"prompt_number":
9
"prompt_number":
8
},
{
"cell_type": "markdown",
...
...
@@ -383,13 +353,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number":
10
,
"prompt_number":
9
,
"text": [
"90"
]
}
],
"prompt_number":
10
"prompt_number":
9
},
{
"cell_type": "markdown",
...
...
@@ -435,13 +405,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1
1
,
"prompt_number": 1
0
,
"text": [
"(90, 'blue')"
]
}
],
"prompt_number": 1
1
"prompt_number": 1
0
},
{
"cell_type": "code",
...
...
@@ -457,13 +427,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1
2
,
"prompt_number": 1
1
,
"text": [
"(93, 'white')"
]
}
],
"prompt_number": 1
2
"prompt_number": 1
1
},
{
"cell_type": "markdown",
...
...
@@ -519,13 +489,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1
3
,
"prompt_number": 1
2
,
"text": [
"(205.02965999999998, 93000)"
]
}
],
"prompt_number": 1
3
"prompt_number": 1
2
},
{
"cell_type": "markdown",
...
...
@@ -562,7 +532,7 @@
"source": [
"Class variables are defined outside the methods.\n",
"\n",
"* It is still refererenced as
**
self.
**
inside the methods."
"* It is still refererenced as
`
self.
`
inside the methods."
]
},
{
...
...
@@ -593,13 +563,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1
4
,
"prompt_number": 1
3
,
"text": [
"80"
]
}
],
"prompt_number": 1
4
"prompt_number": 1
3
},
{
"cell_type": "code",
...
...
@@ -614,13 +584,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1
5
,
"prompt_number": 1
4
,
"text": [
"79"
]
}
],
"prompt_number": 1
5
"prompt_number": 1
4
},
{
"cell_type": "code",
...
...
@@ -637,13 +607,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 1
6
,
"prompt_number": 1
5
,
"text": [
"90"
]
}
],
"prompt_number": 1
6
"prompt_number": 1
5
},
{
"cell_type": "markdown",
...
...
@@ -661,7 +631,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
" print someone\n",
"
>>>
print someone\n",
" <__main__.Person instance at 0x321ebd8>"
]
},
...
...
@@ -690,7 +660,7 @@
"source": [
"Special methods are prefixed and suffixed with double underscores.\n",
"\n",
"* There are methods for adding (
**\\_\\_add\\_\\_**), subtracting (**\\_\\_sub\\_\\_**
), etc."
"* There are methods for adding (
`__add__`), subtracting (`__sub__`
), etc."
]
},
{
...
...
@@ -714,7 +684,7 @@
]
}
],
"prompt_number": 1
7
"prompt_number": 1
6
},
{
"cell_type": "markdown",
...
...
@@ -744,7 +714,7 @@
}
},
"outputs": [],
"prompt_number": 1
8
"prompt_number": 1
7
},
{
"cell_type": "markdown",
...
...
@@ -772,7 +742,7 @@
]
}
],
"prompt_number": 1
9
"prompt_number": 1
8
},
{
"cell_type": "markdown",
...
...
@@ -830,7 +800,7 @@
"\n",
"Example (add two numbers):\n",
"\n",
" stack.push(stack.pop() + stack.pop())"
"
>>>
stack.push(stack.pop() + stack.pop())"
]
},
{
...
...
@@ -849,7 +819,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"%load
programming-course-assignments/calculator
/calculator.py"
"%load
examples
/calculator.py"
],
"language": "python",
"metadata": {
...
...
@@ -858,7 +828,7 @@
}
},
"outputs": [],
"prompt_number":
40
"prompt_number":
19
},
{
"cell_type": "code",
...
...
@@ -926,6 +896,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import HTML\n",
"def css_styling():\n",
" styles = open('styles/custom.css', 'r').read()\n",
" return HTML('<style>' + styles + '</style>')\n",
...
...
@@ -967,13 +938,13 @@
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 2
2
,
"prompt_number": 2
1
,
"text": [
"<IPython.core.display.HTML at 0x
b182306c
>"
"<IPython.core.display.HTML at 0x
24109d0
>"
]
}
],
"prompt_number": 2
2
"prompt_number": 2
1
}
],
"metadata": {}
...
...
This diff is collapsed.
Click to expand it.
examples/calculator.py
0 → 100644
+
24
−
0
View file @
8ad7bada
#!/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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment