Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c4b597d

Browse filesBrowse files
committed
OOP Exercise
1 parent 1da76ec commit c4b597d
Copy full SHA for c4b597d

File tree

Expand file treeCollapse file tree

1 file changed

+28
-30
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-30
lines changed
Open diff view settings
Collapse file

‎lectures/python_oop.md‎

Copy file name to clipboardExpand all lines: lectures/python_oop.md
+28-30Lines changed: 28 additions & 30 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -799,36 +799,6 @@ Aim for clarity, not efficiency.
799799
```{exercise-end}
800800
```
801801

802-
803-
```{exercise-start}
804-
:label: oop_ex2
805-
```
806-
807-
In an {ref}`earlier exercise <pyess_ex2>`, you wrote a function for evaluating polynomials.
808-
809-
This exercise is an extension, where the task is to build a simple class called `Polynomial` for representing and manipulating polynomial functions such as
810-
811-
```{math}
812-
:label: polynom
813-
814-
p(x) = a_0 + a_1 x + a_2 x^2 + \cdots a_N x^N = \sum_{n=0}^N a_n x^n
815-
\qquad (x \in \mathbb{R})
816-
```
817-
818-
The instance data for the class `Polynomial` will be the coefficients (in the case of {eq}`polynom`, the numbers $a_0, \ldots, a_N$).
819-
820-
Provide methods that
821-
822-
1. Evaluate the polynomial {eq}`polynom`, returning $p(x)$ for any $x$.
823-
1. Differentiate the polynomial, replacing the original coefficients with those of its derivative $p'$.
824-
825-
Avoid using any `import` statements.
826-
827-
```{exercise-end}
828-
```
829-
830-
## Solutions
831-
832802
```{solution-start} oop_ex1
833803
:class: dropdown
834804
```
@@ -865,6 +835,34 @@ print(F(0.5))
865835
```{solution-end}
866836
```
867837

838+
839+
```{exercise-start}
840+
:label: oop_ex2
841+
```
842+
843+
In an {ref}`earlier exercise <pyess_ex2>`, you wrote a function for evaluating polynomials.
844+
845+
This exercise is an extension, where the task is to build a simple class called `Polynomial` for representing and manipulating polynomial functions such as
846+
847+
```{math}
848+
:label: polynom
849+
850+
p(x) = a_0 + a_1 x + a_2 x^2 + \cdots a_N x^N = \sum_{n=0}^N a_n x^n
851+
\qquad (x \in \mathbb{R})
852+
```
853+
854+
The instance data for the class `Polynomial` will be the coefficients (in the case of {eq}`polynom`, the numbers $a_0, \ldots, a_N$).
855+
856+
Provide methods that
857+
858+
1. Evaluate the polynomial {eq}`polynom`, returning $p(x)$ for any $x$.
859+
1. Differentiate the polynomial, replacing the original coefficients with those of its derivative $p'$.
860+
861+
Avoid using any `import` statements.
862+
863+
```{exercise-end}
864+
```
865+
868866
```{solution-start} oop_ex2
869867
:class: dropdown
870868
```

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.