diff options
author | Prabhu Ramachandran | 2017-01-23 15:58:50 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2017-01-23 15:58:50 +0530 |
commit | 75fcf9b318fada12be10f9eb567aafae750719ff (patch) | |
tree | 45bb391e3630f563632c9abc72ac0b78f9e8e0a4 | |
parent | c0032d69db78f5003b5263430cf621de42add7bc (diff) | |
download | python-workshops-75fcf9b318fada12be10f9eb567aafae750719ff.tar.gz python-workshops-75fcf9b318fada12be10f9eb567aafae750719ff.tar.bz2 python-workshops-75fcf9b318fada12be10f9eb567aafae750719ff.zip |
Minor changes to basics.
-rw-r--r-- | basic_python/basics.tex | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/basic_python/basics.tex b/basic_python/basics.tex index 79c4946..3016747 100644 --- a/basic_python/basics.tex +++ b/basic_python/basics.tex @@ -62,6 +62,7 @@ In []: p = 3.141592 \item \kwrd{complex} \begin{lstlisting} In []: c = 3+4j +In []: c = complex(3, 4) \end{lstlisting} \end{itemize} \end{frame} @@ -204,7 +205,7 @@ In []: verybig = big * big * big * big \frametitle{Arithmetic operators} \begin{lstlisting} In []: 17 / 2 -Out[]: 8 +Out[]: 8.5 # 8 on Python 2.x In []: 17 / 2.0 Out[]: 8.5 @@ -245,9 +246,11 @@ Out[]: 5.0 In []: c.imag Out[]: 4.0 - In []: c.real Out[]: 3.0 + +In []: c.conjugate() +(3-4j) \end{lstlisting} \end{frame} @@ -452,7 +455,7 @@ Out[]: False In []: int(17 / 2.0) Out[]: 8 -In []: float(17 / 2) +In []: float(17 // 2) Out[]: 8.0 In []: str(17 / 2.0) @@ -486,6 +489,13 @@ In []: a = "# Not a comment!" \begin{frame} \frametitle{Exercise 1} Given a 2 digit integer\ \typ{x}, find the digits of the number. + \vspace*{1em} + + \begin{itemize} + \item For example, let us say \typ{x = 38} + \item Find a way to get \typ{a = 3} and \typ{b = 8} using \typ{x}? + \end{itemize} + \end{frame} \begin{frame}[fragile] @@ -497,6 +507,17 @@ In []: a*10 + b == x \end{lstlisting} \end{frame} +\begin{frame}[fragile] + \frametitle{Another Solution} +\begin{lstlisting} +In []: sx = str(x) +In []: a = int(sx[0]]) +In []: b = int(sx[1]]) +In []: a*10 + b == x +\end{lstlisting} +\end{frame} + + \begin{frame} \frametitle{Exercise 2} Given an arbitrary integer, count the number of digits it has. |