In this project, we're going to write our first piece of code.
It's customary in the programming world that the very first program you write is called, "Hello, World!" The purpose of this program is simple — have the computer print the words, "Hello, World!" on the screen.
Since we're not ones to buck tradition, we're going to make "Hello, World!" our very first project as well. The nice thing about this project is that it's easy to do (it's only one line of code) and it will give us an opportunity to start exploring our Ready Set STEM Development Environment (RDE).
Programming is the process of writing instructions for a computer to follow. You write these instructions using an editing tool (we provide a custom editing tool as part of the Ready Set STEM CREATOR Kit) and then "send" those instructions to the the computer to carry out (or "execute"). Just like there are lots of different languages that people can speak, there are also many languages that computer instructions can be written in — each of which will ultimately be converted into a format that the computer understands.
The CREATOR Kit supports many different programming languages, but we will primarily be focused on one of the most common, called Python. Python is a versatile language that is used in both the academic and the professional worlds to build a varied set of applications and tools. Learning how to program in the Python programming language will provide a solid foundation for all future programming education.
Software is a fancy name for computer code. Typically, we refer to a very big computer program (like an entire game or application) as software, but in reality, even just a single line of code is also considered software.
It's now time to enter the code for this project. In the Code Window, enter the following:
A few things worth noting at this point:
The line number "1" will automatically be visible before you start entering your code (you don't need to enter line numbers). In future projects, we'll only include line numbers in the code boxes when it makes it easier to discuss specific lines of code.
Capitalization generally does matter when you're programming. In this line of code, if the word "print" isn't in all lowercase letters, you may find that your code doesn't work as expected.
It's possible to copy-and-paste code into the Code Window instead of typing it all in. As an example of how you do this, you can copy-and-paste the line above right into your code window. To do that, follow these steps:
Highlight the print('Hello, World!')
line in the code box
above using your mouse
Press and hold the <CTRL> key on your keyboard and press the letter "C" at the same time — this creates a copy of your text
Click in the Code Window where you want to paste the code
Press and hold the <CTRL> key on your keyboard and press the letter "V" at the same time — this pastes the text
Now that you've typed (or copied-and-pasted) the line of code into the Code
Window, let's see if it works. We do this by running the program. To
run the program, click on the Play icon () at the top of the Code Window.
The program runs by starting at the first line, doing what that line says (executing that line), and then moving on to the next line. It does that until it reaches the bottom. In this case, we only have one line, so only that line of code is executed.
It may take a few seconds for the code to run, and you may notice two things during this time:
The triangular PLAY icon turns to a square; and
The little Ready Set STEM icon at the top of the code window spins.
These are just indications that the Raspberry Pi is busy running your code. And don't worry if you don't notice these things — sometimes they happen so fast they they're not very noticeable.
If you've done everything correctly, you should see the following in your Program Output window (the window in the lower left of the RDE, below the Code Window):
Hello, World!
-- PROGRAM FINISHED --
The first line of the output window is the result of the code you've written — you've successfully had the computer print the words "Hello, World!"
The last line indicates that the program is finished running — this will be helpful later when you're writing longer and more complicated programs.
Congratulations! You've just written your first program!
But wait! What if the output from your program doesn't look like it's supposed to? Or if you get a jumbled red and black error-looking message in the Program Output window? If that's the case, you likely have an error in your code.
But, even if your code worked perfectly and you didn't get any errors in your code above, we highly recommend reading , as you're certain to encounter programming errors at some point.
We picked "Hello, World!"
as the text to print — why not
try printing something else?
Try writing a program to print multiple lines of text. For example, a joke:
Q: How many programmers does it take to change a light bulb? A: None, that's a hardware problem.
Try writing some code that doesn't work — that is, a program that generates an error message. Examine the error message to see where your code failed.