Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/07-Errors and Exception Handling/03-Errors and Exceptions Homework - Solution.ipynb
Views: 648
Kernel: Python 3
Errors and Exceptions Homework - Solution
Problem 1
Handle the exception thrown by the code below by using try
and except
blocks.
In [1]:
Out[1]:
An error occurred!
Problem 2
Handle the exception thrown by the code below by using try
and except
blocks. Then use a finally
block to print 'All Done.'
In [2]:
Out[2]:
Can't divide by Zero!
All Done!
Problem 3
Write a function that asks for an integer and prints the square of it. Use a while
loop with a try
, except
, else
block to account for incorrect inputs.
In [3]:
In [4]:
Out[4]:
Input an integer: null
An error occurred! Please try again!
Input an integer: 2
Thank you, your number squared is: 4