12 Days of Python – Day 1
Posted: December 12, 2011 at 5:05 am
Welcome to Day 1 of the 12 Days of Python. This is the first in a series of posts where we will use Python and the Pygame module to draw a Christmas scene. Each day we’ll add something else to the scene, and we’ll show a new aspect of Python or Pygame. We’re also having a Giveaway, where you can win a Kindle Touch!Read More...
12 Days of Python
Posted: December 12, 2011 at 5:04 am
Welcome to the “12 Days of Python”, brought to you by “Hello World! Computer Programming for Kids and Other Beginners”.
12 Days of Python is a series of posts where we will use Python and the Pygame module to draw a Christmas scene. Each day we’ll add something else to the scene, and we’ll show a new aspect of Python or Pygame. The 12 Days are December 12 through 23, 2011.
We’re also having a giveaway, where you can win a Kindle Touch! Details are here. (Update: We have a winner!)
To run the code in the 12 Days of Python, you will need Python and Pygame installed. We’re using Python 2.x. If you use the book’s installer (which installs Python 2.5, Pygame, and some other modules), you’ll have everything you need.
Warren & Carter
Day 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7 Day 8 Day 9 Day 10 Day 11 Day 12
Kindle Touch Giveaway!
Posted: December 10, 2011 at 6:06 am
We’re giving away a Kindle Touch! If you’d like to enter, there are two ways to do so.Read More...
Posted: November 24, 2011 at 11:10 pm
In the book we covered several Python data types, including the ‘list’. There is one that we didn’t cover, called a ‘dictionary’. Dictionaries can be quite useful, so we thought we would explain them in a blog post.
A dictionary is a way of associating two things to each other. These two things are called the “key” and the “value”. Each item or entry in a dictionary has a key and a value. You will hear these referred to as “key-value pairs”. A dictionary is a collection of key-value pairs.Read More...
College for Kids
Posted: July 16, 2011 at 2:37 am
Recently, I (Carter) TA’ed for Dave Briccetti’s College for Kids programming class for 11-to-14-year-olds at Diablo Valley College. We used Python 3 and Kojo Learning Environment (a turtle-based program you can script in Scala). I learned lots from the experience, and it was great working with Mr. Briccetti.
The kids in the class learned about loops, input, if statements, printing, and randomness in Python 3. They also learned about loops, functions, and controlling the turtle in Kojo. I saw lots of interesting projects come out of this. Some people were really creative (for instance, drawing complex pictures with Kojo) while others chose to examine and modify some of the example programs. One student, who I really enjoyed working with, was constantly asking me questions like, “So if I was to make it do one thing if there’s an error, and another if there isn’t, how would I do that?”
The one problem that almost everyone had at some point was typing things in correctly. Kids would call me over asking about some incomprehensible error message, and I would type one character and it …Read More...
Posted: April 21, 2011 at 3:16 am
Many of the games in the book are very simplified versions of classic computer games. LunarLander is an example of that. The original Lunar Lander arcade game was a “vector-graphics” game, where you have to land a lunar module on the moon.There is rocky lunar terrain with a few safe landing spots.You control the rotation and thrust of the lander to make a safe landing.Here’s a screen shot:
The LunarLander in “Hello World!” only moves vertically, not sideways.This was done to show a gravity simulation while keeping the code as simple as possible.After all, the point of the games in the book is to learn, not to make an accurate copy of an old arcade game.We encourage readers to take the games in the book as starting points and extend them in whatever way they like.
I thought it would be fun to take the first step in that direction with LunarLander.So, I made LunarLander2D.This turns LunarLander from a 1-D simulation (vertical only) to a 2-D simulation (vertical and horizontal), more like the arcade version.
To do that, there are two major things that needed to change:
Need to keep track of both vertical and horizontal speed
Need a way to rotate the lander, so …
Hello World! Chinese Translation
Posted: March 14, 2011 at 7:16 pm
A few days ago we received a few copies of the Chinese translation of “Hello World”. Here’s what the cover looks like:
It’s pretty cool so see our book published in other languages. The book is published in China by Turing, which is a division of the Posts and Telecom Press. You can see their web page for the book here:
What to do if you’re having problems.
Posted: February 27, 2011 at 7:59 pm
Every programmer, new or not, will encounter some difficulties. If this happens, we’re here to help! Here are the top 3 things to look for when programs have an error.
Proper version of Python and all required modules. Did you use our book’s installer to get Python? If not, get the installer here and follow the instructions.
Indentation. Make sure spacing is correct. This is very important in Python.
Check for typos. A silly thing like a spelling error or typing _ instead of – might cause your program to have an error. Make sure it matches the one in the book.
If you still can’t figure it out, leave a comment on our blog, post a question on our Author Forum, or e-mail us at firstname.lastname@example.org . We do our best to get back to you within 48 hours.
Cool stuff for Mac
Posted: September 23, 2010 at 11:11 pm
Recently, I got a Mac. This means I’ll be able to help a lot more with Mac problems on our author forums and on this blog. In related news, here’s a cool trick for Macs only. You can make your program talk to you! Start by importing os. OS is a module that lets you interact with your computer’s operating system. Then, type the following:
os.system(“say Hello World!”)
This will send a command to Mac OS telling it to, well, say, “Hello World!” You can put whatever you want after say. However, apostrophes (‘) don’t seem to work. If you have one in your string, it won’t say anything at all. Here’s an example program:
os.system(“say Whats your name?”) #For some reason, apostrophes don’t work.
name = raw_input(“What’s your name?”)# It’s good to put it on the screen as well,# in case users don’t have their speakers on.
print “Hi, “+name+”, hows it going?”
os.system(“say Hi, “+name+”, hows it going?”)
I hope this brings a whole new level of interaction to all your future programs!
Carter SandeRead More...
Carter Teaches Random
Posted: June 30, 2010 at 5:16 am
Dave Briccetti, who, among other things, teaches programming to kids, is teaching a Python class for Grade 7-9 students this summer at College for Kids. He asked if we would be interested in doing a “guest lecture” to his class. So Carter presented an introduction to randomness and the Python Random module. You can see the video on Dave’s site, here:http://young-programmers.blogspot.com/2010/06/randomness-in-python-lesson-by-carter.htmlRead More...