Commit 2db3e07f authored by Raffaele Grosso's avatar Raffaele Grosso
Browse files

Update Python exercises' solution in notebook

parent 942f781d
This diff is collapsed.
......@@ -185,16 +185,14 @@ $\lgblksquare\lgwhtsquare\lgblksquare\lgwhtsquare\lgblksquare\lgwhtsquare\lgblks
\Chapter{Exception handling}
Write a program that reads a number from a file and then devides 100 by this number.
Write a small Python script -- \texttt{inverse.py} -- (or a function -- \texttt{inverse} -- in an interactive shell) which reads a number from the text file given as argument and outputs its inverse.
\begin{enumerate}[label=\textbf{\alph*)}]
\item Try opening a non-existent file. Make sure you understand what happens.
\item Same as above, but this time you don't want the program to terminate but to
print an error message.
\sitem In addition to the previous point, your program should not terminate but print out a different error statement
for the different possible error cases (generate them by varying the content of the file).
\sitem Add an action to be executed in case an error occured, which were not catched by previous \texttt{except} statements.
\sitem Add an action to be executed at any execution of the try statement.
\item Run your script passing first a non-existent file and then a file containing a $0$-charachter. Make sure you understand what happens in both cases.
\item Modify the script so that it does not terminate when given a non-existent file as argument but let it print an error message instead.
\sitem In addition to the previous point, your program should not terminate but print out a different error statement
for the different possible error cases (trigger them by varying the content of the file or the argument passed to the script).
\sitem Add an action to be executed in case an error occured, which were not catched by previous \texttt{except} statements.
\sitem Add an action to be executed at any execution of the try statement.
\end{enumerate}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment