Now,
hopefully, you've already got everything set up so that you're ready to go on the Day 1 tasks, and you're
able to see what I'm seeing right here.
Now, if you don't know what I'm talking about, or if you don't have access to any of this, be sure
to go back to the previous lesson where I showed you, step-by-step, 'How to Download' and get hold of
the latest version of the Curriculum Exercises on PyCharm. So be sure you do that before you proceed,
so that we're all starting at the same place and you're seeing exactly what is shown in the videos,
and we're ready to start learning how to program.
Now, remember that the whole reason why we're learning to program is to be able to tell the computer
what it needs to do, and for it to follow our commands.
So let's go ahead and tell the computer to do something.
And we're going to do that by writing our first line of code.
So in this case I'm creating something called a "print function", which is just the word print all in
lowercase and then followed by a set of parentheses().
Now inside these parentheses, I'm going to tell it what I want it to print.
And hopefully it's going to output that inside our console.
So I'm going to start off by writing the classic "Hello world!" inside here,
and then once you're ready then go ahead and click Run.
After a few seconds you should see the computer follow your command, namely printing the words that
you told it to print inside the console or the output area over here.
And once it's done, it indicates that by writing, "Process finished with exit code 0", which means
everything was successful, everything was run without any issues.
Now, just to break down this area a little bit more for you, if you look at the top line here, which
you'll always, always see, there's a lot of text in here, but it's actually very simple to understand.
Essentially, it's telling you the location of the current file that is being run that has resulted in
this output.
So in our case, it's the Day 1 task.
And you'll see this change as you go through the different days
because the location of this file, where you wrote the code, will change.
So the first line is the location of the file that you executed.
The second line, or multiple lines in between, is the result of your command to the computer.
And then finally at the very, very end, it tells you if the process finished with success, which
is in this case, or if there are any other issues, it would show up here as well, which we're going
to see very, very shortly.
And to be sure that you're always running the current file, make sure that this drop down is selected
as Current File,
and that way, every time you press the play button here, it will run the code into the output area.
Now if you want to do a shortcut and you're really into keyboard shortcuts, you can hover over the
play button and you'll see the shortcut on what I'm using, which is a Mac, is Control + R, in Windows
or Linux,
it'll show up different shortcuts, but it should all show up there if you want to try that out.
Alternatively, just keep pressing the play button and it works just as well.
And the way that this command works is super simple.
You have the keyword, "print", followed by a set of parentheses, and then inside the parentheses, you
tell it what you want it to print.
And once you've inserted that, then when this line of code gets executed by the computer, it'll know
to simply print or output the thing that you've placed in between the parentheses.
But notice here that it's not just the word, "Hello world!", that I've put inside my parentheses,
I've also added some quotation marks or double quotes around the word,
and the reason why I've done this is so that I can tell the computer that this bit here, in between
the double quotes, is not code.
It's not like print where it's supposed to do something,
this is just some text that I've made up, that I want it to print out.
And these pieces of text in programming lingo, is known as "Strings".
And you can imagine it as almost like a pearl necklace.
Right?
It's a string of characters.
And what the double quotes do, is they basically show the beginning and the end of that string of characters.
So that means you have to be really careful when you're typing.
For example, if I go ahead and I miss out the closing double quote, well, now you can see that there's
some changes that have happened to our code already, namely that the last parentheses, instead of
being colored in white like the opening parentheses or how it used to be, it's now colored in green,
the same color as the rest of our text or our string.
And this is a subtle hint to us.
You're going to get really attuned to these subtle hints, because they are the clues that will tell
you what might have gone wrong in your code.
If I run this code as it is right now, it's going to break.
It's going to give me a SyntaxError, and it says something that seems like it's completely not English.
So how can we figure out what this means?
Now, the thing I want you to know is that all programmers make mistakes.
We all make lots of errors, like forgetting to add the double quotes at the end of the string, or
forgetting to add a closing parentheses.
These things are just common errors because we're human.
But the thing that differentiates great programmers is we're really good at figuring out what the problem
is and how to fix it.
So you can imagine that coding is just a whole bunch of problems that you have to solve.
And in this case, when we get some sort of red text, and our code is not doing what we expect it to do,
then all we have to do is take this entire error message where it says something, something error,
and this is some sort of message that we're supposed to understand, and we're simply going to drop
it into Google.
And usually the first link you come across will be from a website called stackoverflow.com.
And this is basically the Q&A website that all developers will go to whenever something is wrong with
their code, or when they can't figure out how to do something.
So if we click on this link, you can see that somebody else has also had this error,
and some kind souls have told us that the solution might be the fact that you're missing a double quote
before the end of the line.
So if we take a look back at our code, the code that generated this error looks like this.
And indeed, we are missing a double quote at the end of our string.
As you're learning to code, as you're going through your 100 Days, I want you to become more and more
attuned to the color of your code, because one of the most helpful things that code editors such as
this do for us is something called, "Syntax highlighting".
For example, when I was missing that double quote, it highlighted this entire thing and that is basically
it telling us, it seems like this whole thing is some text.
It thinks that all of this is a string and that we're missing a closing parenthesis.
So if you notice this and you're like, wait, actually that's not right,
this part should match the color of the open brace, which is white.
So there must be something wrong here.
And indeed, if you have a look at the error message, it actually has a little caret sign right here
showing you that there's something that's probably not right here.
And it might jog your memory that, "Oh yeah, I've forgotten a closing double quote."
Now, the really handy thing about PyCharm is it actually underlines your errors before you even run
your code.
And if you hover over the underline, it usually gives you some intelligent guess as to what your problem
might be.
And in this case, it's absolutely spot on.
It says, you're missing a closing quote, which is exactly what we're missing.
So that will also be really helpful for us to figure out what it is that we need to do.
But as with all things with AI, if we don't know what we're doing in the first place, these hints
don't help us that much.
For example, if I put the closing quote right here, I've got other problems and I'm going to create
more problems for myself.
So it's important that we first understand how things work and then use technology and AI to help us,
such as in this case, to fix our bug.
Now, you'll notice that there is also a tiny squiggly line under this closing brace, but in this case,
it's not in red, so it's not an error, but instead it's in yellow, which is a warning.
Now, most of these warnings come from a good standard practice for how to write code.
And if we hover over this warning, it tells us that PEP 8, which is guidance for how to write
Python code, and it tells you that the problem that it's seeing is there's no new line at the end of
the file.
Now, we can ignore all of this because it's a bit too complicated, and it's actually very simple to
solve this problem.
All it's saying is that in good practice, when we're writing Python code, there should be a new line
at the end of the file so that we have our cursor down here instead of ending right there.
And that's all there is to it.
And with that one thing, we've gotten rid of all our errors,
we've gotten rid of all our warnings,
our code looks good stylistically, as well as syntactically.
All these big words that all that it means is that it looks great in every single way.
And we've got our little check mark, which means no problems found by the editor.
Now, sometimes the editor can be really picky, and some of the things that it tells you, you can safely
ignore,
but as always, we need to understand how everything works before we can do that.
So now that we've embarked on our first step to write some code and start commanding the computer to
do what we want it to do, which is to print out some words into the output area,
it's now time for a challenge.
So head over to the next lesson, and we're going to test you on what you've learned in this lesson
by practicing writing some print statements.
So for all of that and more, I'll see you on the next lesson.