\section{Exercises}
\begin{footnotesize} 

\subsection*{Targeted exercises} 
\subsubsection*{Exercises for Section \ref{Exploiting_built-in_methods_to_manipulate_data_stored_in_objects}} 
\begin{enumerate}\setcounter{enumi}{-1}
	\item  Make a Numpy array that has all integers from 14 to 1, including both 1 and 14.  Assign this to the variable \lstinline{pH}.  Use \cite{methods} of Numpy arrays to accomplish the following (you may need to read the online Numpy documentation):

	\begin{itemize}
		\item Calculate the mean.
		\item Calculate the variance of the array.
		\item Get the standard deviation of the array.
		\item Sort the array so that they increase monotonically.
		\item Round the value of the \lstinline{conc_H} array to tens digit.
	\end{itemize}


\end{enumerate}
\subsubsection*{Exercises for Section \ref{Importing_subsets_of_libraries_using_from}} 
\begin{enumerate}\setcounter{enumi}{0}

    \item If you only want to do some math on individual values, then it may not make sense to import the whole \cite{Numpy} library. Write import statements to only import the following functionality from Numpy. For example, if you wanted to import the function that is needed in order to create a Numpy array, and then make an array of the integers 1--10, assigning it to the variable \lstinline{x}, you can use:\\
    \lstinline{from numpy import array}\\
    \lstinline{x = array([1,2,3,4,5,6,7,8,9,10])}

    Using this pattern, accomplish the following:
    \begin{enumerate}  
        \item Import the function to compute the sine of an angle, and use it to operate on \lstinline{x}.  
        \item Import the function to compute the natural logarithm and use it to operate on \lstinline{x}.  
        \item Import the function to compute the exponential and use it to operate on \lstinline{x}.  
        \item Import the function to compute the square root and use it to operate on \lstinline{x}.  
    \end{enumerate}
\end{enumerate}

\subsubsection*{Exercises for Section \ref{Performing_multiple_assignment_operations_in_one_line_by_unpacking}} 
\begin{enumerate}\setcounter{enumi}{1}
	\item  Pick three people you know. Using a single assignment operation assign their favorite food to a variable that is their first name. 

    \item Define variables for the masses of hydrogen, carbon, nitrogen, and oxygen in a single line.

	\item  A function that is native to Python that we have not yet seen is \lstinline{divmod()}. Using the information returned by Python \lstinline{help()} function, learn how to write a single line of code that will use \lstinline{divmod()} to solve the following problem: You have a solvent bottle with 289 mL of solvent.  You have a series of experiments to run that each require 7 mL of solvent. How many experiments can you run, and how much solvent will be left over. These should be assigned to separate variables. Again, use only a single line of code. 
\end{enumerate}


\subsubsection*{Exercises for Section \ref{Representing_answers_to_yes/no_questions_using_booleans}} 
\begin{enumerate}\setcounter{enumi}{4}
	\item  Which of the following are valid values of booleans?

	\begin{enumerate}
	\item True
	\item true
	\item TRUE
	\item Yes
	\item yes
	\item YES
	\item 1
	\item 0
	\item Maybe
	
	\end{enumerate}
\end{enumerate}


\subsubsection*{Exercises for Section \ref{Describing_the_location_of_files_or_folders_on_your_computer_using_Pathlib}} 
\begin{enumerate}\setcounter{enumi}{5}
	\item  Write down a \textbf{statement} to create a variable folder name that contains a Path object object pointing to the following folders on your computer.  Use the \lstinline{print(<path objet>)} to print the absolute path for each:
    \begin{enumerate}
        \item Your Downloads folder.
	\item Your Documents folder.
	\item The folder where you are storing files for this book. This \textit{must} be different from both the Downloads and Documents folder.
    \end{enumerate}

\end{enumerate}
\subsubsection*{Exercises for Section \ref{Making_paths_convenient_and_portable_by_specifying_relative_paths}} 
\begin{enumerate}\setcounter{enumi}{6}
	\item  For the following combinations of folders, print out the relative paths that point from the first folder to the second folder.  Use the \lstinline{.relative_to()} \textbf{method} of the Path class to find the relative path between them.  You may need to use the \lstinline{walk_up = True} \textbf{keyword argument}. When interpreting the results, realize that  two periods in a row (\lstinline{..}) indicates the folder one level up from the current folder:
    \begin{enumerate}
        \item From Downloads to Documents
	\item From Documents to Downloads
	\item From the folder you are using for this book to your Downloads folder
	\item From the folder you are using for this book to your Documents folder
    \end{enumerate}
    
\end{enumerate}


\subsubsection*{Exercises for Section \ref{Adding_codechembook_to_your_Python_installation}} 
\begin{enumerate}\setcounter{enumi}{7}
	\item  Verify that \lstinline{import codechembook} will run. Then use \lstinline{help(codechembook)}. How many submodules are there in this library?

\end{enumerate}


\subsubsection*{Exercises for Section \ref{Locating_files_and_folders_graphically_with_codechembook.quickTools.quickOpenFilename}} 
\begin{enumerate}\setcounter{enumi}{8}
	\item  In this exercise, you will learn how to use \lstinline{quickOpenFilename()} to generate a relative path from one file or folder to another file or folder.
    \begin{itemize}
        \item Use \lstinline{quickOpenFilename()} to select a file in your Documents folder. This will return an absolute path to the file. Assign this absolute path to a variable called \lstinline{path1}.
	\item Do the same for a file in your Downloads folder, but assign it to the variable \lstinline{path2}.
	\item Use the \lstinline{.relative_to()} method of the \lstinline{Path} class to get the relative path from \lstinline{path2} to \lstinline{path1}.  Note you will want to use the \textbf{keyword argument} \lstinline{walk_up} to allow full flexibility for relative paths.
    \end{itemize}


\item  Modern file dialogs have search features that make it so that you don't have to click through your whole file structure to find a file or folder and get its path.  Use the search feature of the file dialog in \lstinline{quickOpenFilename()} to search for the file `0.999.csv' used in this chapter and select it to get the absolute path to it.  Confirm that this path exists.

\end{enumerate}


\subsubsection*{Exercises for Section \ref{Accessing_data_in_structured_text_files_using_Numpy}} 
\begin{enumerate}\setcounter{enumi}{10}
	\item  Use the following files supplied on \website for this exercise. Read them into Python using \lstinline{genfromtxt()}.
    \begin{enumerate}
        \item Stress-Strain1.csv
	\item Stress-Strain1.tsv
	\item Stress-Strain1.ssv
    \end{enumerate}

    
\item  Repeat Exercise 11, but only for the .csv file. Assign what is returned from \lstinline{genfromtxt()} to a single variable. Then using this variable, unpack the values into variables that correspond to the columns in the original data file.

\item  Use \lstinline{genfromtxt()} read the same .csv file you used in Exercise 11, but extract only the second column of data.

\item  As you would have noticed, the first two rows in the .csv file used in Exercise 11 contained header information. Get the information for each row, using the \lstinline{genfromtxt()} function and setting \lstinline{unpack = False}. You may also want to know that there are two other keyword arguments that will be useful: \lstinline{max_rows} and \lstinline{dtype}. The last of these specifies the type of data you are trying to read, which in this case is a string (\lstinline{str}).

\end{enumerate}

\subsubsection*{Exercises for Section \ref{Making_appealing_and_interactive_plots_using_Plotly}} 
\begin{enumerate}\setcounter{enumi}{14}
	\item  Go to the Plotly website and find an example plot. Explain how you might use that type of plot in your own research. 

	\item  Run \lstinline{plotlyTest()} from \lstinline{codechembook} after importing it using \lstinline{from codechembook plotlyTest import plotlyTest}. You can always use \lstinline{help(codechembook)} to find this function.

	\item  The  \lstinline{plotlyTest()} function you ran in  Exercise 16 above should have opened a figure in your computer's browser. One nice thing about Plotly is that these figures are interactive. Using your mouse, move your mouse cursor over the data shown.  What happens? Then, click and drag your mouse to try select a region of data.  What happens? Play around with this interactivity, and describe what else you find you can do.

\end{enumerate}


\subsubsection*{Exercises for Section \ref{Outlining_your_solution_before_coding_using_comments}} 
\begin{enumerate}\setcounter{enumi}{17}
	\item  Consider the Comprehensive exercises for this chapter (see below). 
    \begin{enumerate}
        \item Create a text outline for the solution, formatted as Python comments.
	\item Create a flow diagram for the solutions.
	\item Write a list of instructions, like you would to a human being, for how to solve them.
    \end{enumerate}
\end{enumerate}


\subsection*{Comprehensive exercises} 
\begin{enumerate}\setcounter{enumi}{18}
	\item  Generate Plotly plots of the following relationships:
    \begin{enumerate}
        \item $e^{-x}$
	\item $1/x$
	\item $\nu_{rms}$ vs $T$ using a Maxwell-Boltzman distribution for $\ce{N2}$, over the temperature range of 200 K to 400 K 
	\item $K_{EQ}$ as a function of $T$, for $\Delta{H}=100$ kJ$\cdot$mol$^{-1}$ and $\Delta{S}=-50$ J$\cdot$mol$^{-1}\cdot$K$^{-1}$ over the temperature range of 300 K to 400 K.
    \end{enumerate}


    
\item  Consider the decay of fluorescence intensity ($I$) over time ($t$). This typically follows the functional form $I(t) = Ae^{-kt}$. Using Plotly and the values $A = 0.1$, $k = 2$:
    \begin{enumerate}
        \item Plot $I$ versus $t$ over the range $t = 0$ to $t = 10$.
	\item Plot ln($I$) vs $t$.
	\item Plot $I$ vs ln($t$).
	\item Plot ln($I$) versus ln($t$).
	\item Which of the above is the most useful, and why do you think that?
    \end{enumerate}

\item  The data file `CO2-IR.txt' found on the book's companion website (\website) contains an absorption-mode FTIR spectrum of gaseous $\ce{CO2}$ with the $x$-axis in wavenumbers. Write a script to that outputs a plot of \%transmission vs wavenumber. Remember that absorbance = $-\log_{10}$(transmission). Make sure you use correct axis labels! Bonus: Make the $x$-axis run from the largest to smallest numbers, which is the convention for plotting wavenumbers.

\item  Using the same file from  Exercise 21  change the $x$-axis from wavenumber to wavelength (nm) and plot absorption versus wavelength. When converting between wavenumber and wavelength on the $x$-axis, you will need apply a Jacobian correction to the absorption. You can do this by $I(\lambda) = I(\nu) 1 \times 10^7 / \nu^2$ . Make sure you use correct axis labels! 

\item  One nice feature of Plotly over Matplotlib is the fact that you can change a plot after you show it and get an updated version.  In Matplotlib, once you show a plot, you usually can no longer make changes and you have to start over.  In the case of the final code presented in this chapter, the Plotly figure object, \lstinline{fig}, is still in your computer's memory and you can update it.  To prove that you can do this, run the code and adjust the $x$-axis range to 450-750 nm using the \lstinline{range} keyword of the \lstinline{update_xaxes()} \textbf{method} of the figure object. Then show the plot again.  Then, do the same for the $y$-axis, choosing values for \lstinline{range} so that the resulting spectrum fills the plot area.

\item  In this chapter, we introduced a function that makes it easy to identify files on your computer: \lstinline{quickOpenFilename()}. This will be nice to use when you don't know where the file is located, or when you are choosing different files each time you run your script.  However, there will be times when you simply want to use the same file over and over---for instance when you are developing and testing a code. In these cases, it can be much faster to provide the path to the file in the script. Modify the final code in this chapter, replacing the \lstinline{quickOpenFilename()} function with a line that creates a Path object with the absolute path to the data. Verify this works, and also comment on when you might prefer this approach over the use of \lstinline{quickOpenFilename()}.

\end{enumerate}
\end{footnotesize} 
