Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Tackle 4 errors using Python's try/except blocks.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Hi, again, Megan here.
0:09
In this practice session, you're going to
practice catching and handling errors.
0:11
Let's take a look.
0:16
Here, in app.py, you can see I have
four different errors for you to handle.
0:18
The first one,
a string with tree inside of it,
0:24
is trying to be converted to an integer.
0:27
The second one is a float that is
a string trying to be converted to
0:31
an integer as well.
0:35
The third one is a list
with five items in it, and
0:38
you're trying to access the fifth index.
0:42
Remember, indexes start at 0, so
0:45
this would be 0,1,2,3, 4.
0:49
So, index of 5 does not exist.
0:53
And then, this last one here,
I put a little reminder,
0:57
I want you to enter a non-number.
1:01
So, it's going to request for
you to input how many hats you own.
1:05
I want you to put anything but a number.
1:09
And then, when it tries to convert it,
it's going to give you an error.
1:11
So, go ahead and
try tackling these on your own,
1:15
and I will see you in the next video.
1:18
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up