- [Instructor] In this self-check exercise,
I'd like you to take a look at the try it function
and figure out before you execute the code down below
what is going to be displayed if we pass this function 10.7
and what is going to be displayed
if we pass this function, the string Python.
So, just to show you down below here,
we're going to define the same function
that you see here,
and then, we're going to call it
with those two values.
So, pause the video and think about that for a moment,
and then come back to see the answer.
Okay, let's go ahead and define the function,
and before I execute the next two snippets,
let's talk about this.
So, we're going to first pass in the value 10.7,
which we will receive as the parameter value.
We're going to convert that floating point value
into an integer,
so the value 10 will get assigned to x.
Because that's going to be a valid conversion,
this except clause will be skipped,
and we'll jump down to the else clause
to print that the integer representation
of 10.7 is,
and then we'll display 10.
So, let's go ahead and execute that just to confirm.
And indeed, the integer representation
of 10.7 is 10.
Now, let's talk about the string Python.
So, that string will be assigned to the parameter value.
When we try to convert that to an integer, hell...
or Python, excuse me, is not a valid integer.
So, this will result in a value error.
The try suite will terminate,
so if there were additional statements after this one,
they would not execute.
We'll jump to the first except handler,
which matches the type of exception
that's going to be thrown,
and in that case, we will display
10.7 could not be converted to an integer.
The else clause will not execute,
and the function will terminate.
So, let's just try that to make sure,
and indeed, we get Python could not be converted
to an integer.