\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 4}

\medskip

\medskip
\hrule

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

\noindent
\begin{enumerate}
\item
Consider the following expressions. For each expression, first determine whether the expression
is \textit{well-formed} or not. For each well-formed expression, determine if the expression will
be successfully evaluated by Python or not. For each expression that is successfully evaluated,
determine its value and the type of its value.
Assume that the \texttt{math}, \texttt{random}, and \texttt{sys} modules have all been imported prior to
the execution of these expressions.
Also, suppose that the value of \texttt{sys.maxint} is \texttt{9223372036854775807}.
\begin{itemize}
\item[(a)] \verb+len(str(random.randint(1, 4)*22))+
\vspace{0.25in}
\item[(b)] \verb!sys.maxint+2!
\vspace{0.25in}
\item[(c)] \verb+5 < 8 and (100/(len("0")-1))+
\vspace{0.25in}
\item[(d)] \verb+abs(5 - 25) < 15 and 0.5+
\vspace{0.25in}
\item[(e)] \verb!2/math.trunc(1.5)+200L!
\vspace{0.25in}
\item[(f)] \verb+5 < 8 or (100/(len("0")-1))+
\vspace{0.25in}
\item[(g)] \verb+bin(len(str(10<20)))+
\vspace{0.25in}
\item[(h)] \verb!4L*len("Problem1")/(len("Exam1")%3)+2.0!
\vspace{0.25in}
\item[(i)] \verb!-4*-3**2+-len(str(66))!
\vspace{0.25in}
\item[(j)] \verb+bool(math.sqrt((-1)**100))+
\end{itemize}

\newpage

\item 
We have defined a function called \texttt{factorSum} whose header is:

\centerline{\texttt{def factorSum(n):}}

The parameter \texttt{n} is expected to be a positive integer and the function returns the
sum of all the factors of \texttt{n}.
For example, if \texttt{n} were 10, the function would return 18 (which is 1 + 2 + 5+ 10). 

Now, here is a definition. A positive integer $n$ is called \textit{perfect} if the sum 
of all the factors of $n$, excluding $n$, is equal to $n$.
For example, $n = 6$ is perfect because its factors, excluding 6, are 1, 2, and 3 and 1+ 2 + 3 = 6.

For this problem, we want you to write a function called \texttt{nextPerfect} with the following
function header:

\centerline{\texttt{def nextPerfect(M):}}

You can assume that the parameter \texttt{M} is a positive integer.
This function should return the smallest perfect integer that is greater than or equal to \texttt{M}.
This function should call \texttt{factorSum} repeatedly to complete its task.


Here is an example that will help you understand what is being asked of you.\\
\noindent
\textbf{Example.}
The first four perfect integers are 6, 28, 496, and 8128.
So if we call \texttt{nextPerfect(10)}, it should return 28.
Even if we call \texttt{nextPerfect(20)}, the function should return 28.
In fact, even if we call \texttt{nextPerfect(28)}, the function should return 28.
However, if we call \texttt{nextPerfect(29)}, the function should return 496.

\vspace{4in}
\end{enumerate}

\medskip
\hrule
\end{document}
