\documentclass{article}

\usepackage{amsmath}
\usepackage{listings}
\usepackage{framed}
\usepackage{amssymb}
\usepackage{graphicx}

\addtolength{\textwidth}{1in}
\addtolength{\evensidemargin}{-0.5in}
\addtolength{\oddsidemargin}{-0.5in}
\addtolength{\textheight}{1in}
\addtolength{\topmargin}{-0.5in}

\begin{document}

\noindent
\centerline{\Large\bf 22C:16 (CS:1210) Quiz 5}

\medskip

\medskip
\hrule

\medskip
\noindent
You have 20 minutes to complete this quiz.

\noindent
\begin{enumerate}
\item Consider the following function definition.
\begin{framed}
\begin{verbatim}
def test(a, b, c = 20, d = "12"):
    return str(b) + str(c) + d + a
\end{verbatim}
\end{framed}
For each of the function calls below, first write down if the function
call causes an error or not.
If you determine that the the function call does cause an error,
write down a 1-sentence explanation as to why this is so.
If you determine that the function call does not cause an error,
then write down (i) the values that the
parameters of \texttt{test} take on and (ii) the value that is returned
by the function.
\begin{itemize}
\item[(a)] \texttt{test(10)}

\vspace{1in}

\item[(b)] \texttt{test(10, "20")}

\vspace{1in}

\item[(c)] \texttt{test("20", 10)}

\vspace{1in}

\item[(d)] \texttt{test(test("1", 2), c = 3, b = "5")}

\vspace{1in}

\item[(e)] \texttt{test(b = 40, a = str(40))}
\end{itemize}

\newpage

\item Consider the following program
\begin{framed}
\begin{verbatim}
def foo(x, y = 2):
    global z
    z = 12
    return x + y - z

x = 10
y = 15
z = 11
y = foo(z - x + 1)
print x + y - z

z = foo(z - x + 1, z)
print x + y - z
\end{verbatim}
\end{framed}
\begin{itemize}
\item[(a)] What is the output of this program when it is executed.

\vspace{1.5in}

\item[(b)] Now delete the \texttt{global z} statement from the function \texttt{foo}.
What is the output of this modified program when it is executed?

\vspace{1.5in}

\end{itemize}
\end{enumerate}

\medskip
\hrule
\end{document}
