First, you can start Python in Windows by clicking on Start>Programs>Python 3.x>IDLE. Go ahead, try it...I’ll wait here. IDLE is software that helps you to communicate with the computer. It is on the outside of the main program, just as a snail’s shell is on the outside of the snail. Whack on a snail’s shell and he will get the message. IDLE works in the same way. Enter commands into IDLE and it will send the message to your computer. IDLE acts as your interpreter and translates what you say into a language that the computer can understand. If you really want to know, IDLE stands for Ineractive DeveLopment Environment. Why did they choose the L in the middle of the word, “development?” I have no idea and it’s not important for the purposes of this book, so let’s move on and get over it.
There are two windows to work from in IDLE. There is the Edit Window and the Shell Window. The Python Shell window will say, “Python Shell” at the top of the window, while the Edit window will say, “Untitled” and have a “run” command listed on the top menu bar. If Python starts in the Shell Window and you want to use the Edit Window, just choose File
There are other editors that you can use for programming but to keep things simple in this book we will use the IDLE software that is packaged with Python.
Why are there two windows in IDLE and how do I use them? Python allows you to work in script mode or in interactive mode. What’s the difference?
Most people use both of these together. Script mode for working on their main program and interactive mode for trying new ideas in the same way you would use scratch paper.
A third function of IDLE is that it is also a debugger. You can find the debugger button at the top of the Shell window. What’s a debugger? It’s a program to help you kill bugs. No not the one crawling up your leg; but the bugs, or problems, that are in the code we are working on
Did you notice that IDLE changes the colors of your text? What’s the meaning? Let’s look at a list of some of the most common syntax colors and their meanings in IDLE.
You needn’t memorize these at this point, but knowing the meaning of the colors can help you see clearly where you typed something wrong. If you were trying to type a string and its not green, you probably forgot the quotation marks or did something else the computer didn’t like. The colors can also be changed according to your personal preferences and may vary in different editors.
While we are looking at the windows, how is your text arranged? The text is arranged in lines, groups, and blocks. A block is just a group of code that goes together. Like a city block, it can be divided into smaller groups like houses on the block, cars on the block, dogs, lions, etc. on that block. This concept is important to tell the computer how to read and follow your code. To a computer, arranging your code with the proper grouping of lines and blocks is like a map that says; “first do this, second do that, or repeat this. “
Blocks are one way we dictate the running order in programming. You can have blocks in blocks just as you can have groups in groups. You may have a group of students under 100 years old. But, within that group you may have another group called “girls.” Inside of that group you may have another group or block called “girls with green hair.” Blocks make it easy to keep things or instructions in our code together in their correct group. This helps us refer to them and to direct the computer to use that group of instructions, in the order we want the computer to use them. Blocks are defined by the number of spaces used to indent each line of code. In the following examples I will use dots to show you clearly how many spaces would be in the code. This; “…” refers to three spaces. Use spaces, not dots, when you type your code.
The number of times we indent helps the computer know how we are grouping the information. (Hang in there, a few more ideas and you will make your first game).
Whatever the number of spaces you choose, keep it consistent so you don’t get confused. Why do we care about blocks and grouping programming statements? Ah, I’m glad you asked, but I won’t tell you until later. (Don’t worry you will get to play with these shortly).