Skip to content

Commit

Permalink
Revised part02 for the June 2014 course.
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Jun 22, 2014
1 parent 4f9467f commit 2f5a2a9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 35 deletions.
11 changes: 0 additions & 11 deletions ex02c.py

This file was deleted.

12 changes: 12 additions & 0 deletions ex02d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def greet(name):
"""
A friendly function.
"""
if name == "Antonio":
print ("Welcome Back!")
else:
print ("Greetings, " + name + "!")

# greet the instructors
greet("Riccardo")
greet("Antonio")
74 changes: 50 additions & 24 deletions part02.tex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
\begin{frame}[fragile]
\frametitle{String literals, II}
Multi-line strings are delimited by three quote characters.
\begin{lstlisting}
\begin{lstlisting}[showstringspaces=false]
>>> a = """This is a string,
... that extends over more
... than one line.
Expand Down Expand Up @@ -204,7 +204,7 @@
\frametitle{Operators, IV}
The ``\texttt{\%}'' operator is also used for \emph{string
formatting}:
\begin{lstlisting}[showstringspaces=false]
\begin{lstlisting}
>>> "This is slide ~\alt<2>{\HL{\%d}}{\%d}~ of %d" % (~\alt<2>{\HL{11}}{11}~, 32)
'This is slide 11 of 32.'
>>> "We are ~\alt<3>{\HL{\%.1f}}{\%.1f}~%% done." % (~\alt<3>{\HL{100.0 * 11/32}}{100.0 * 11/32}~)
Expand All @@ -227,27 +227,27 @@
\end{frame}


\begin{frame}[fragile]
\frametitle{Expressions}
% \begin{frame}[fragile]
% \frametitle{Expressions}

Expressions are combinations of operations that manipulate values
and return some other values. (Function calls are operations, too.)
% Expressions are combinations of operations that manipulate values
% and return some other values. (Function calls are operations, too.)

\+
For instance, \texttt{2+2} is an expression, as are
\texttt{abs(-2)}, \texttt{os.path.exists('/tmp')},
\texttt{1 + (1.0/2) + 2**(-2)}
% \+
% For instance, \texttt{2+2} is an expression, as are
% \texttt{abs(-2)}, \texttt{os.path.exists('/tmp')},
% \texttt{1 + (1.0/2) + 2**(-2)}

\+
\emph{Not all Python constructs return a value.}
(Assignment, for example, does not.)
% \+
% \emph{Not all Python constructs return a value.}
% (Assignment, for example, does not.)

\+\scriptsize
References:
\url{http://lambda-the-ultimate.org/node/1044#comment-10878}
\url{http://docs.python.org/reference/expressions.html}
% \+\scriptsize
% References:
% \url{http://lambda-the-ultimate.org/node/1044#comment-10878}
% \url{http://docs.python.org/reference/expressions.html}

\end{frame}
% \end{frame}


\begin{frame}[fragile]
Expand Down Expand Up @@ -519,7 +519,13 @@
\begin{exercise}
Type the same code in a file named \texttt{hello.py}, then type
\texttt{import hello} at the interactive prompt.
What happens?
What happens? Type \texttt{import hello} again; what happens?
\end{exercise}

\+
\begin{exercise}
At the terminal, type \texttt{python hello.py}. What happens?
Type it again; what happens?
\end{exercise}
\end{frame}

Expand All @@ -536,6 +542,13 @@
\+
\textbf{Modules are only read once}, no matter how many times an
\texttt{import} statement is issued.
\begin{lstlisting}
>>> import hello
Hello, world!
>>> import hello
>>> import hello
\end{lstlisting}

\end{frame}


Expand All @@ -553,7 +566,9 @@
To import definitions into the current namespace, use the
`\texttt{from $x$ import $y$}' form:
\begin{lstlisting}
>>> from fractions import Fraction
>>> from hello import greet
>>> greet("Bob")
Hello, Bob!
\end{lstlisting}
\end{frame}

Expand Down Expand Up @@ -643,8 +658,12 @@
statement.

\+
If a loop is exited via a \texttt{break} statement, the
\texttt{else} clause is \emph{not} executed.
Use the \texttt{continue} statement anywhere in the indented
block to jump back to the \texttt{while} statement.

% \+
% If a loop is exited via a \texttt{break} statement, the
% \texttt{else} clause is \emph{not} executed.

% \+
% The \texttt{else} clause is optional.
Expand All @@ -653,8 +672,15 @@

\begin{frame}
\begin{exercise}
Modify the \texttt{greet()} function to print ``Welcome back!'' if
the argument \texttt{name} is your name.
In the \texttt{hello.py} file, modify the \texttt{greet()}
function to print ``Welcome back!'' if the argument \texttt{name}
is your name.

\+
Insert at least two distinct invocations of the function with
different names at the end of the file. Check that everything
works by running \texttt{python hello.py} at the terminal prompt.
(Or \emph{Ctrl+Shift+F10} in PyCharm.)
\end{exercise}
\end{frame}

Expand Down

0 comments on commit 2f5a2a9

Please sign in to comment.