\section{Exercises}
\begin{footnotesize} 
\subsection*{Targeted exercises} 
\subsubsection*{Exercises for Section \ref{Making_ordered_collections_of_data_more_flexible_using_list_objects}} 

\begin{enumerate}\setcounter{enumi}{-1}
	\item  Make a list that contains no items.

	\item  Make a list that contains, in order, the Numpy array([1, 2, 3]), the string 'frog', and the number 3.14.

	\item  Make a Numpy array with 20 elements from 0 to 10 and convert it to a list.

	\item  Make a list that has twelve items with 1, 2, 3 repeating four times without typing in twelve numbers  (i.e., use the arithmetic properties of lists).

	\item  Make a list that has four items, where each item is the lists that you just made in Exercises 0-3.

    \item  Lists have a property known as  \textbf{mutability}, which means they can be changed after assignment (for more information see Chapter \ref{DataTypes}).  In many programming languages, if you want to make a copy of list or arrays, you simply assign it to a new variable. You might make a list and assign it to the variable \lstinline{A}, then use \lstinline{B = A} to copy it to a new variable. Then you could change \lstinline{A} and \lstinline{B} independently. What happens when you do this for a list in Python? 

    \item  Lists have a property known as  \textbf{mutability}, which means they can be changed after assignment (for more information see Chapter \ref{DataTypes}). One consequence of this is that a function can change the list, and this can result in changes that are accessible outside the function. Write a function that will accept a list as an argument, and then the function replaces the first element in the list with the string \lstinline{"this element was changed inside a function"}.  Make a list, print this list. Pass the list to the function, and then print the list again. 


\end{enumerate}
\subsubsection*{Exercises for Section \ref{Combining_lists_by_concatenation}} 
\begin{enumerate}\setcounter{enumi}{6}
	\item  How many items would be in the list that was made by concatenating all five lists you made in Exercises 0-4?

	\item  Repeat Exercise 3 using concatenation.

	\item  Add the number 5 to the end of the list you made in Exercise 1.

	
\end{enumerate}
\subsubsection*{Exercises for Section \ref{Adding_items_to_lists_using_the_append_method}} 
\begin{enumerate}\setcounter{enumi}{9}

        \item How many items would be in the list that was made by appending the lists you made in Exercises 1-4 onto the list made in Exercise 0?

        
	\item  Repeat Exercises 7-9 using \lstinline{.append()} instead of concatenation.

	



\item  Sometimes it would be better to use a list, and sometimes a Numpy array.  In the following cases, which do you think would be better, and why?
    \begin{enumerate}
        \item You want two variables to hold the $x$ and $y$ points, respectively, of an X-ray diffraction pattern.

        \item You are doing a titration experiment that involves saving UV-vis spectra for each titration point, and you want to keep a record of the files that you saved, but you don’t know how many files you will need to save.

        \item You want a single variable to store the history of responses of a user to a code that periodically asks them  to record the lab temperature.

        \item You finished the experiments being discussed in this chapter and now you want to write a code that plots only the intensity of the spectrum at 450 nm (a single value) vs. the titration equivalent for each spectrum.  You want to store the intensity points and titration equivalents as two separate variables for plotting.
    \end{enumerate}

\end{enumerate}
\subsubsection*{Exercises for Section \ref{Determining_the_number_of_items_in_a_collection_using_the_len_function}} 
\begin{enumerate}\setcounter{enumi}{12}
	\item  Prove that your answer to Exercise 7 is correct, using \lstinline{len()}.

	\item  Starting from an empty list, create a list that goes from 0 to 4 using only \lstinline{append()} and \lstinline{len()}

	
\end{enumerate}
\subsubsection*{Exercises for Section \ref{Access_items_in_lists,_arrays,_or_strings_by_indexing}} 
\begin{enumerate}\setcounter{enumi}{14}
	\item  Create the following list and store it in a variable named \lstinline{data}: $[5, 1, 9, 4, 2, 8, 2, 7]$

	\begin{enumerate}
	\item What is the index of the item containing 4?
	\item What does the \textbf{expression} \lstinline{data[4]} yield?
	\item Write an expression that yields the item containing the value 8.
	\item Write an expression that yields the third-to-last item in the list, and will do so, even if the length of the list changes.
	\item Replace the number 4 with the number 6.
	
	\end{enumerate}
    
\end{enumerate}



\subsubsection*{Exercises for Section \ref{Access_subsets_of_lists,_arrays,_or_strings_by_slicing}} 
\begin{enumerate}\setcounter{enumi}{15}
	\item  Create a list containing \lstinline{['yes', True, None, 3, 5.5, 'no']}:

	\begin{enumerate}
	\item Write an expression that yields a subarray containing the first five items of the array.
	\item What does the \cite{expression} \lstinline{data[2:5]} yield?
	\item Write an expression to create new list containing every other item in this list, starting with the second item.
	\item Write an expression to save the third through sixth items of the list as a new list stored in a variable named \lstinline{data_reduced}.
	\item Write an expression that yields the last four items in the list and will work even if the length of the list changes (but continues to have at least 4 items).
	
	\end{enumerate}
\end{enumerate}


\subsubsection*{Exercises for Section \ref{Ordering_lists_and_arrays_by_sorting}} 
\begin{enumerate}\setcounter{enumi}{16}
	\item  Make the following list: \lstinline{[12, 6, 0, 2, 31, 4, 7]}.

	\begin{enumerate}
	\item Sort this list to run in increasing order.
	\item Using resources outside of this book, find and use the \textbf{keyword argument} that lets you sort the same list in the reverse order.
	\end{enumerate}
\end{enumerate}


\subsubsection*{Exercises for Section \ref{Obtaining_a_list_of_paths_using_codechembook.quickTools.quickOpenFilenames}} 
\begin{enumerate}\setcounter{enumi}{17}
	\item  Using \lstinline{quickOpenFilenames()}, print the paths for all the files in your downloads folder. 

	\item  Using the \lstinline{filetypes} keyword argument in \lstinline{quickOpenFilenames()}, print paths for \textit{only} the pdf files in your downloads folder. If you don't have any pdf files in your downloads folder, then download a scientific paper as a pdf, add it to your downloads and try this exercise again.  

	
\end{enumerate}
\subsubsection*{Exercises for Section \ref{Creating_collections_of_objects_with_customized_organization_using_dictionaries}} 
\begin{enumerate}\setcounter{enumi}{19}
	\item  Create a dictionary in which the keys are the atomic numbers of the atoms on the second row of the periodic table, and the values are the atomic symbols.

	\begin{enumerate}
	\item Write an expression to get the atomic symbol of fluorine from this dictionary.
	\item Write an expression to produce a string containing the formula for lithium fluoride using only this dictionary.
	\item Add hydrogen and helium to this dictionary
    \end{enumerate}

\item  Make dictionaries of solvent properties for Benzene.  Each entry of the dictionary should be a different property, and you should choose keys that have descriptive names to make it easy to remember which key goes with which property.  The properties you need are: 

    \begin{enumerate}
	\item The IUPAC name
	\item The molecular weight
	\item The boiling point
	\item The density
    \end{enumerate}
    
\item  Repeat Exercise 20, but for the following solvents.

    \begin{enumerate}
	\item Benzene
	\item Cyclohexane
	\item $n$-Hexane
	\item Toluene
	\item Methanol
	\item Acetonitrile
    \end{enumerate}
    
\item  Create a dictionary where the keys are the names of the solvents and the values are the dictionaries that you made in Exercises 21 and 22. This means you are creating a dictionary that holds other dictionaries---a behavior known as \ul{nesting}.

\end{enumerate}


\subsubsection*{Exercises for Section \ref{Accessing_information_about_objects_using_attributes}} 
\begin{enumerate}\setcounter{enumi}{23}
	\item  Starting with the list of files in your Downloads folder that you generated in Exercise 18, sort this list and then, use the \lstinline{stem} attribute of Path objects to print just the filename (without the extension) of the first file.

	\item  Numpy arrays also have attributes.  Create a Numpy array from 0 to 5 with 0.2 spacing.  Using the \lstinline{size} attribute, print the number of elements of this array.

\end{enumerate}


\subsubsection*{Exercises for Section \ref{Performing_repetitive_operations_using_for_loops}} 
\begin{enumerate}\setcounter{enumi}{25}
	\item  Using a \lstinline{for} loop, print each item in the list that you made in Exercise 4 on a separate line.

	\item  In Exercise 19, we found all the pdf files in your downloads folder.  The output would be unwieldy.  Using a \lstinline{for} loop, place each on its own line.

	\item  Suppose you have the list \lstinline{[3, 6, 2, 7, 5]}.  Using two nested \lstinline{for} loops, print out the products of all pairs of items in the list.  In other words, you will want a series of text output like: \lstinline{6 x 2 = 12}.  Note that you should have 25 total output statements.

\end{enumerate}


\subsection*{Comprehensive exercises} 
\begin{enumerate}\setcounter{enumi}{28}
	\item  Make a single Plotly plot that shows the Maxwell-Boltzmann distribution for N$_2$ at 11 different temperatures equally spaced between $0^\circ$F and $100^\circ$F. The atmosphere is mostly nitrogen, and so these curves represent how fast the majority of molecules in the atmosphere are moving under various 'typical' conditions. 

	\item  Make a single Plotly plot that shows the Maxwell-Boltzmann distribution for N$_2$, O$_2$, Ar, CO$_2$, Ne, He, CH$_4$, Kr, and H$_2$ at room temperature. These are the major components of the atmosphere. 

	\item  Modify the final code in this chapter so that it produces a plot of each spectrum as a separate image and saves each one as a different file, all using a single \lstinline{f}or loop.

	\item  You now see that there are multiple properties for lines in Plotly. Let’s practice using them.  You can use the online Plotly documentation or the Plotly technical chapter (Chapter \ref{ch:plotly}) to learn about other formatting. Modify the final code of this chapter to: 

	\begin{enumerate}
	\item Change the colors of the lines to ones that we have not yet used.
	\item Change the line width to a value that we have not used yet.
	\item Make the lines dashed, rather than solid or dotted.
	\item Change the font for the entire figure to `Courier New.'
	\item Change the font size so that it appears roughly double the default font size.
	\item Change the $x$-axis range to span from 270 nm to 1000 nm.
\end{enumerate}
\end{enumerate}
\end{footnotesize} 
