You wanted code, well now you have it! Using the "Hello World" lesson from the tutorial I am currently using, I crafted the simple yet nifty bit of code you see below.
One of my main reasons for starting this blog was to describe the way a non-programmer thinks about and works through introductory programming. I have to be honest though, the above code was simple. For the most part, it was just a matter of typing in the command print, followed by a string (the green stuff in quotes), and if necessary the mathematical expression (the purple numbers with orange mathematical operators). In order to see how this code actually works, you need to run the program. Because I am using TextMate, it is painfully easy for to run this program and view the output. All I need to do is press Command + R and TextMate runs the program for me:
I realize that not all of you have access to TextMate, so I also decided to run the program using the command line (which I figured is a bit more universal in nature). Note that when I say command line, I mean in the Unix sense a la Terminal. For all you Windows users, sorry but I gave up windows a long time ago so this will be of no help to you. Anyhow, all you need to do to run the Python program from the command line is open up Terminal, navigate to where the Python file (.py extension) is located using the cd command, and then type python hello_world.py, where hello_world.py is the name of the Python program you wish to run. If you need a little more help with navigating around your computer in Terminal, see Using The Terminal with Ubuntu or Getting to the know the Terminal. Here is an example of what running a Python program in terminal looks like:
You can ignore the orange lines and focus on the stuff in green. Notice that I saved the hello_world.py file on my Desktop. I navigated to my Desktop by opening up Terminal and typing in cd Desktop. From here, I ran the Python program by typing python hello_world.py. As you can see, the program ran, and all the information that was called by the print command in the hello_world.py file was printed on the screen.For the next few posts, I will refer to this post when I mention running a Python program. There are multiple ways to go about running a Python program, but I will let you explore the alternatives.
0 Responses to "Commence Coding"
Post a Comment