Skip to content

Commit

Permalink
fixed oop images
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLeoni committed Nov 20, 2018
1 parent 6e3761c commit 0c1dff2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 23 deletions.
Binary file added exercises/oop/img/complex-numbers-addition.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/oop/img/complex-numbers-definition.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/oop/img/complex-numbers-equality.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/oop/img/complex-numbers-magnitude-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/oop/img/complex-numbers-magnitude-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 18 additions & 21 deletions exercises/oop/oop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7ff4343f8208>\n"
"<__main__.ComplexNumber object at 0x7fa9bc769320>\n"
]
}
],
Expand Down Expand Up @@ -796,7 +796,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7ff4343f8208>\n"
"<__main__.ComplexNumber object at 0x7fa9bc769320>\n"
]
}
],
Expand Down Expand Up @@ -911,6 +911,8 @@
"source": [
"### 2.3. Defining methods\n",
"\n",
"#### 2.3.1 phase\n",
"\n",
"Let's make our class more interesting by adding the method `phase(self)` to operate on the complex number:"
]
},
Expand Down Expand Up @@ -986,7 +988,7 @@
"\n",
"**WARNING:** Put round parenthesis in method calls!\n",
"\n",
"When _calling_ a method, you MUST put the round parenthesis after the method name like in `c.phase_()_`! \n",
"When _calling_ a method, you MUST put the round parenthesis after the method name like in `c.phase()`! \n",
"If you just write `c.phase` without parenthesis you will get back an address to the physical location of the method code: \n",
"\n",
"```\n",
Expand All @@ -1000,6 +1002,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2.3.2 log\n",
"\n",
"We can also define methods that take more than one parameter, and also that create and return `ComplexNumber` instances, like for example the method `log(self, base)`:"
]
},
Expand Down Expand Up @@ -1081,7 +1085,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7ff4343f8c18>\n"
"<__main__.ComplexNumber object at 0x7fa9bc769860>\n"
]
}
],
Expand Down Expand Up @@ -1137,7 +1141,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.4. A better print with `__str__`"
"#### 2.3.3 `__str__` for printing"
]
},
{
Expand All @@ -1156,7 +1160,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7ff4343f85c0>\n"
"<__main__.ComplexNumber object at 0x7fa9bc7698d0>\n"
]
}
],
Expand Down Expand Up @@ -1316,15 +1320,15 @@
"source": [
"**EXERCISE:** There is another method for getting a string representation of a Python object, called `__repr__`. Read carefully [\\_\\_repr\\_\\_ documentation](https://docs.python.org/3/reference/datamodel.html#object.__repr__) and implement the method.\n",
"\n",
"**QUESTION**: Would `3.0 + 5.0i` be a valid Python expression ? Should we return it with `__repr__`? Read again also [\\_\\_str\\_\\_ documentation]([`__repr__ documentation`](https://docs.python.org/3/reference/datamodel.html#object.__str__)\n",
"**QUESTION**: Would `3.0 + 5.0i` be a valid Python expression ? Should we return it with `__repr__`? Read again also [\\_\\_str\\_\\_ documentation](https://docs.python.org/3/reference/datamodel.html#object.__str__) \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.5. ComplexNumber code skeleton\n",
"### 2.4. ComplexNumber code skeleton\n",
"\n",
"We are now ready to write methods on our own. Open Visual Studio Code (no jupyter in part B !) and proceed editing file `ComplexNumber_exercise.py` \n",
"\n",
Expand All @@ -1340,7 +1344,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.6. Complex numbers magnitude\n",
"### 2.5. Complex numbers magnitude\n",
"\n",
"![](img/complex-numbers-magnitude-1.png)\n",
"![](img/complex-numbers-magnitude-2.png)"
Expand Down Expand Up @@ -1380,7 +1384,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.7. Complex numbers equality\n",
"### 2.6. Complex numbers equality\n",
"\n",
"Here we will try to give you a glimpse of some aspects related to Python equality, and trying to respect interfaces when overriding methods. Equality can be a nasty subject, here we will treat it in a simplified form.\n",
"\n",
Expand Down Expand Up @@ -1477,7 +1481,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.8. Complex numbers isclose\n",
"### 2.7. Complex numbers isclose\n",
"\n",
"Complex numbers can be represented as vectors, so intuitively we can determine if a complex number is close to another by checking that the distance between its vector tip and the the other tip is less than a given delta. There are more precise ways to calculate it, but here we prefer keeping the example simple."
]
Expand Down Expand Up @@ -1544,7 +1548,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.9. Complex numbers addition\n",
"### 2.8. Complex numbers addition\n",
"\n",
"![](img/complex-numbers-addition.png)\n",
"\n",
Expand Down Expand Up @@ -1579,7 +1583,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.10. Adding a scalar\n",
"### 2.9. Adding a scalar\n",
"\n",
"We defined addition among ComplexNumbers, but what about addition among a ComplexNumber and an `int` or a `float`? \n",
"\n",
Expand Down Expand Up @@ -1664,7 +1668,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2.11. Complex numbers multiplication\n",
"### 2.10. Complex numbers multiplication\n",
"\n",
"![](img/complex-numbers-multiplication.png)\n",
"\n",
Expand Down Expand Up @@ -1698,13 +1702,6 @@
" self.assertEquals(3 * ComplexNumber(1,2), ComplexNumber(3,6)); \n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
4 changes: 2 additions & 2 deletions exercises/testing/testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
"\n",
"\n",
"----------------------------------------------------------------------\n",
"Ran 1 test in 0.002s\n",
"Ran 1 test in 0.001s\n",
"\n",
"FAILED (failures=1)\n"
]
Expand Down Expand Up @@ -462,7 +462,7 @@
"+ [0]\n",
"\n",
"----------------------------------------------------------------------\n",
"Ran 2 tests in 0.002s\n",
"Ran 2 tests in 0.003s\n",
"\n",
"FAILED (failures=2)\n"
]
Expand Down

0 comments on commit 0c1dff2

Please sign in to comment.