diff --git a/oop/oop.pdf b/oop/oop.pdf index c971291d8c8d79f10f6086dea0403ceb70c8e94c..8a050dc67b85c38b79995f14a434238e3718ae8c 100644 Binary files a/oop/oop.pdf and b/oop/oop.pdf differ diff --git a/oop/oop.tex b/oop/oop.tex index bea459874fbfb1f3ec48d822c43d32b01abe38b8..9fc382897336842a7a6ef35f633d3e5d360732a6 100644 --- a/oop/oop.tex +++ b/oop/oop.tex @@ -192,7 +192,7 @@ create new instances of a class. \begin{minted}{python} origin = Vector() v1 = Vector(2, 1) -print v1.x, origin.y +print(v1.x, origin.y) \end{minted} \bigskip @@ -224,7 +224,7 @@ class Vector(object): \item we agree not to access this attribute directly: \begin{minted}{python} >>> v1 = Vector(1, 2) ->>> print v1._secret # this is forbidden +>>> print(v1._secret) # this is forbidden \end{minted} \end{itemize} @@ -254,7 +254,7 @@ origin.distance(v1) \begin{frame}[fragile]{Print representation of an object} \begin{minted}{python} >>> v1 = Vector(4, 3) ->>> print v1 +>>> print(v1) <__main__.Vector object at 0x7f41ab878450> \end{minted} @@ -267,7 +267,7 @@ origin.distance(v1) when using the \mintinline{python}{print} function; \item we are in control of what is printed, e.g., for the vector class: \begin{minted}{python} ->>> print v1 +>>> print(v1) <4, 3> \end{minted} \end{itemize} @@ -297,7 +297,7 @@ class Vector(object): \item get the type of an instance: \begin{minted}{python} >>> v1 = Vector(4, 3) ->>> print type(v1) +>>> print(type(v1)) \end{minted} %% start minted fix \vspace{-.08cm} @@ -306,20 +306,20 @@ class Vector(object): \item that also works for the class: \begin{minted}{python} ->>> print type(Vector) +>>> print(type(Vector)) <type 'type'> \end{minted} \item use \mintinline{python}{isinstance()} to check if an object is a vector: \begin{minted}{python} ->>> print isinstance(v1, Vector) +>>> print(isinstance(v1, Vector)) True \end{minted} \item what happens here: \begin{minted}{python} ->>> print v1.distance(4) +>>> print(v1.distance(4)) \end{minted} \end{itemize} \end{frame} @@ -328,7 +328,7 @@ True \begin{itemize} \item define special operators like: \mintinline{python}{+,-,==,<,>,len(),...} -see: \path{https://docs.python.org/2/reference/datamodel.html#basic-customization} +see: \url{https://docs.python.org/3/reference/datamodel.html#basic-customization} \item these can be \textcolor{pms280_compl}{overloaded} to work with your class (keep it sensible); @@ -357,7 +357,7 @@ class Vector(object): \begin{minted}{python} >>> v1 = Vector(1, -6) >>> v2 = Vector(3, 4.5) ->>> print v1 + v2 +>>> print(v1 + v2) <4, -1.5> \end{minted} \end{frame} @@ -415,8 +415,8 @@ containing two integers: \mintinline{python}{numerator} and \bigskip -see: \path{https://github.com/lumc-python/oop} \\ -or go directly to: \textcolor{pms280_compl}{\path{https://classroom.github.com/a/8BnbL9fD}} +see: \url{https://github.com/lumc-python/oop} \\ +or go directly to: \textcolor{pms280_compl}{\url{https://classroom.github.com/a/8BnbL9fD}} \end{frame} \end{document} diff --git a/oop/solutions.pdf b/oop/solutions.pdf index b689a6849ddbd678d1b4e44ad368bf2256dea791..cec8026d501ed24bf30c66729f4ed56775a8ec5b 100644 Binary files a/oop/solutions.pdf and b/oop/solutions.pdf differ diff --git a/oop/solutions.tex b/oop/solutions.tex index 6e95e628fd047536b88a7d6ab4e6f2d2ed803503..d938f0018f6aa362451fb862b8ec4333b4bb673c 100644 --- a/oop/solutions.tex +++ b/oop/solutions.tex @@ -28,7 +28,7 @@ \author{Jonathan~K.~Vis} \institute[LUMC]{Dept. of Human Genetics, Leiden University Medical Center} -\date{September 21st, 2017} +\date{} \title{Solutions --- Object Oriented Programming} \begin{document} @@ -75,7 +75,7 @@ class Fraction(object): \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(1, 2) +>>> print(Fraction(1, 2)) 1/2 \end{minted} \end{frame} @@ -102,7 +102,7 @@ class Fraction(object): \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(1, 2) + Fraction(2, 3) +>>> print(Fraction(1, 2) + Fraction(2, 3)) 7/6 \end{minted} \end{frame} @@ -130,7 +130,7 @@ class Fraction(object): \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(1, 2).invert() +>>> print(Fraction(1, 2).invert()) 2/1 \end{minted} \end{frame} @@ -151,14 +151,14 @@ class Fraction(object): return Fraction(self._denominator, self._numerator) def to_float(self): - return float(self._numerator) / float(self._denominator) + return self._numerator / self._denominator \end{minted} \vfill \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(1, 2).to_float() +>>> print(Fraction(1, 2).to_float()) 0.5 \end{minted} \end{frame} @@ -174,17 +174,17 @@ class Fraction(object): return Fraction(self._denominator, self._numerator) def to_float(self): - return float(self._numerator) / float(self._denominator) + return self._numerator / self._denominator def integer(self): - return int(self._numerator) / int(self._denominator) + return self._numerator // self._denominator \end{minted} \vfill \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(7, 6).integer() +>>> print(Fraction(7, 6).integer()) 1 \end{minted} \end{frame} @@ -197,10 +197,10 @@ class Fraction(object): ... def to_float(self): - return float(self._numerator) / float(self._denominator) + return self._numerator / self._denominator def integer(self): - return int(self._numerator) / int(self._denominator) + return self._numerator // self._denominator def __sub__(self, other): return Fraction(self._numerator * other._denominator - @@ -212,7 +212,7 @@ class Fraction(object): \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(1, 2) - Fraction(2, 3) +>>> print(Fraction(1, 2) - Fraction(2, 3)) -1/6 \end{minted} \end{frame} @@ -226,7 +226,7 @@ class Fraction(object): ... def integer(self): - return int(self._numerator) / int(self._denominator) + return self._numerator // self._denominator def __sub__(self, other): return Fraction(self._numerator * other._denominator - @@ -242,7 +242,7 @@ class Fraction(object): \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(1, 2) * Fraction(2, 3) +>>> print(Fraction(1, 2) * Fraction(2, 3)) 2/6 \end{minted} \end{frame} @@ -271,7 +271,7 @@ class Fraction(object): \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(1, 2) / Fraction(2, 3) +>>> print(Fraction(1, 2) / Fraction(2, 3)) 3/4 \end{minted} \end{frame} @@ -290,8 +290,8 @@ class Fraction(object): def simplify(self): divisor = gcd(self._numerator, self._denominator) - self._numerator = self._numerator / divisor - self._denominator = self._denominator / divisor + self._numerator = self._numerator // divisor + self._denominator = self._denominator // divisor return self \end{minted} @@ -299,7 +299,7 @@ class Fraction(object): \texttt{test\_fraction.py} \begin{minted}{python} ->>> print Fraction(2, 6).simplify() +>>> print(Fraction(2, 6).simplify()) 1/3 \end{minted} \end{frame}