Now the next step
and the next tip is pretty obvious. When the editor's giving you an error or when
the console is giving you an error, fix the errors before you continue.
Now, this is a little bit easier when you're dealing with errors in the editor,
because it will actually highlight to you the line that's broken.
So here we've got a print statement and when we hover over it,
it tells us that it expected an indented block. So that should be a good enough
clue to tell us what's actually wrong.
So if we go ahead and indent this block, then that error goes away.
But that's not the only error, no. When you run this code,
you still get another error. So let's say that I am a 12-year-old girl,
we get another error.
And this error does not show up when we write the code,
but it only shows up depending on what input we gave to this age variable.
So now we have a different type of error. We have an error that's in the console.
How do we solve this error? Well,
the easiest way is just to select the parts of the error
that's not specific to your code like this age greater than 18 or line 84,
but the part that is pretty much common to whenever anybody gets this error.
And now if we copy it and we paste it into Google,
then you can see there's a lot of other people who've had this issue.
And if we read what the problem is,
it tells us that you're getting the input from the console as a string
and you must cast that input as an int
before you try to do these numerical operations like comparisons. Back over here,
that's exactly what we're trying to do on line 84 right here.
This age comes out of this input function and it returns a string.
And so in order to turn this into a number,
we of course have to cast it or type convert it into an integer.
And now when we run our code and we give it our age,
it no longer errors out.
And if I tell it that I am in fact 21,
which is still not my real age,
then we actually get the print statement working.
But remember that the errors don't always solve all of your bugs, like this.
In this case there are no errors with my code whatsoever,
it's just not doing what I want it to do.
And these are the most frustrating bugs to debug because nobody is helping you
here. There is no errors that you can Google,
there's no underlines that you can check.
You actually have to rely on your skills as a programmer to fix this.
Now we, of course, know that this needs to be an fstring in order to insert that
variable into this position in the curly braces.
But if you didn't, then this would be a lot harder to debug.
Experience comes in really handy with debugging and the more bugs that you
solve, the better you get at it. So go onto the internet,
try to help people in Stack Overflow. Go on to the discord channel for the course,
try to solve other people's bugs and you will find yourself getting stronger
and better day by day.