1-Comments

Before we start to write code I have a question for you. Who do you think will have to read the code that you are going to be writing?

My list of who might need to read your code

So the important idea here is that we will need to communicate with both the COMPUTER and HUMANS. The easiest way to communicate with other humans is using a common language (English in our case). But do computers understand English? Not really. Try running the code below.

This is my greeting program. It writes a good morning message to my friend Hank.

print("Good morning Hank!")

What happened? I’m guessing it gave you an error message. Why do you think that this happened?

Is “This is my greeting program. It writes…” something that the computer would understand? Nope! That message was for you, me and any other human. It is a useful message because it helps all the humans to understand what the purpose of your program is. But you computer has no idea what you are asking it to do. So when it tries to run this code it gets confused and has to quit which is why you get an error message.

This problem is solved using comments. If we put the ‘#’ symbol at the start of a line it tells the computer that this is a message for humans and that it can be ignored. Let us retry the previous code.

# This is my greeting program. It writes a good morning message to my   # friend Hank.

print("Good morning Hank!")

Success! We will use comments throughout our coding projects so you will get more familiar with why we use them and how they are useful.