tag:blogger.com,1999:blog-6148804316836319542024-03-05T01:08:37.756-08:00Computer Programming for Kidswsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-614880431683631954.post-70064075193606753012011-12-11T23:24:00.000-08:002011-12-11T23:26:56.874-08:00We've Moved!We've Moved! You can find our new blog <a href="http://helloworldbookblog.com/">here</a>.<br /><br />And check out our "12 Days of Python", with a chance to win a Kindle Touch!<br /><br /><br />Warren & Carterwsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com3tag:blogger.com,1999:blog-614880431683631954.post-5190850816540317682011-07-15T19:37:00.000-07:002011-07-15T19:43:18.876-07:00College for Kids<div><span>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 <span class="yiv229515038Apple-style-span"><a rel="nofollow" target="_blank" href="http://www.kogics.net/sf:kojo">Kojo Learning Environment</a> (a turtle-based program you can script in Scala)</span>. I learned lots from the experience, and it was great working with Mr. Briccetti.<br /></span></div><div><span><br /></span></div><div>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?"</div><div><br /></div><div>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 would work. Remember, always make sure you type in the example properly if there's a problem.</div><div><br /></div><div>I also did a presentation of functions. You can watch it on the<a rel="nofollow" target="_blank" href="http://young-programmers.blogspot.com/2011/07/carter-sande-teaches-python-functions.html"><span class="yiv229515038Apple-style-span"> Young Programmers Podcast</span></a>.</div>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com3tag:blogger.com,1999:blog-614880431683631954.post-65996820963926901832011-04-20T20:16:00.000-07:002011-04-21T16:52:17.262-07:00LunarLander 2<p class="MsoNormal">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.<span style=""> </span>There is rocky lunar terrain with a few safe landing spots.<span style=""> </span>You control the rotation and thrust of the lander to make a safe landing.<span style=""> </span>Here’s a screen shot:</p><p class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOWLMpToAmQfGj4dWLBYV-kwFOV5hfaUkaUsxOonV7EQeALXsMAOmFpZqVIHRlKBeXXG99v1uiEA3bhb55DM6cSO6cOZljDxk0Dqqo-EDQyI-dk1CuGecMdSXFv3N7478ivifJUxayM2A/s1600/lunarlander_arcade_screenshot.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOWLMpToAmQfGj4dWLBYV-kwFOV5hfaUkaUsxOonV7EQeALXsMAOmFpZqVIHRlKBeXXG99v1uiEA3bhb55DM6cSO6cOZljDxk0Dqqo-EDQyI-dk1CuGecMdSXFv3N7478ivifJUxayM2A/s320/lunarlander_arcade_screenshot.jpg" alt="" id="BLOGGER_PHOTO_ID_5597877285728137458" border="0" /></a></p> <p class="MsoNormal"> </p> <p class="MsoNormal">The LunarLander in “Hello World!” only moves vertically, not sideways.<span style=""> </span>This was done to show a gravity simulation while keeping the code as simple as possible.<span style=""> </span>After all, the point of the games in the book is to learn, not to make an accurate copy of an old arcade game.<span style=""> </span>We encourage readers to take the games in the book as starting points and extend them in whatever way they like.</p> <p class="MsoNormal"> </p> <p class="MsoNormal">I thought it would be fun to take the first step in that direction with LunarLander.<span style=""> </span>So, I made LunarLander2D.<span style=""> </span>This turns LunarLander from a 1-D simulation (vertical only) to a 2-D simulation (vertical and horizontal), more like the arcade version.</p> <p class="MsoNormal"> </p> <p class="MsoNormal">To do that, there are two major things that needed to change:</p> <ul><li>Need to keep track of both vertical and horizontal speed</li><li>Need a way to rotate the lander, so you can thrust in different directions to steer</li></ul> <p class="MsoNormal"> </p> <p class="MsoNormal">Of course, once you start doing rotation and applying thrust at different angles, you need some trigonometry to do the calculations.<span style=""> </span>That’s the main reason we didn’t make LunarLander a 2-D simulation in the first place.<span style=""> </span>We didn’t want to make trigonometry a requirement for the book.<span style=""> </span></p> <p class="MsoNormal"> </p> <p class="MsoNormal">I had to dust the cobwebs off my knowledge of trig.<span style=""> </span>I found the trickiest part was figuring out how to draw the rocket flames at an angle when the lander is rotated.<span style=""> </span>The code to do that is written in an “expanded” form.<span style=""> </span>That is, the code could be made much more compact, but I’m trying to show step-by-step how I’m doing the calculation.<span style=""> </span></p> <p class="MsoNormal"> </p> <p class="MsoNormal">Here are the main differences from LunarLander to LunarLander2:</p> <ul><li>The window is wider, to make room for the sideways motion.</li><li>The lander is now a sprite, which makes it easier to do the rotation (using pygame.transform.rotate)</li><li>The thrust is controlled by pressing/holding the spacebar instead of using the mouse to drag a slider (There are no longer any mouse events.)</li><li>The rotation is controlled by the left and right arrow keys</li><li>A good landing now depends on both speed and angle</li></ul> <p class="MsoNormal"> </p> <p class="MsoNormal">The code is shown below, and you can easily cut-and-paste it into your favourite Python editor to try it out.<span style=""> </span>(I use SPE.) Don’t forget to put a copy of the image file (lunarlander.png) in the same folder as the code when you try to run it.</p><p class="MsoNormal">Here's a screenshot:<br /></p><p class="MsoNormal"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-RR5ikvVb8pIRVWxnAGKPRujpHX8_UwILgac96FWbbI9U7rXbKx8YjF10riGIKB5IqaeLGNg_86-GnqXoXF4jHfFCRRlj8QuDcxsWz6sskg4gIXaQrWF2S6iIwKXfWYMc9Uh7xAZ0WjY/s1600/lunarlander2dscreenshot.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 248px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-RR5ikvVb8pIRVWxnAGKPRujpHX8_UwILgac96FWbbI9U7rXbKx8YjF10riGIKB5IqaeLGNg_86-GnqXoXF4jHfFCRRlj8QuDcxsWz6sskg4gIXaQrWF2S6iIwKXfWYMc9Uh7xAZ0WjY/s320/lunarlander2dscreenshot.jpg" alt="" id="BLOGGER_PHOTO_ID_5598188746921346162" border="0" /></a></p> <p class="MsoNormal"><span style=""> </span></p> <p class="MsoNormal"> </p> <p class="MsoNormal">This is still a very simplified version.<span style=""> </span>Here are some ways it could be enhanced:</p> <ul><li>Add some animation or different sprites when the lander lands roughly or crashes</li><li>Add different messages depending on how the landing was</li><li>Add more terrain and multiple landing spots</li><li>Have multiple turns, where it gets more difficult each time (steeper terrain, smaller landing spots, less fuel, etc.)</li></ul> <p class="MsoNormal"> </p> <p class="MsoNormal">Enjoy!</p><br /><br /><div style="border: 2px solid black; overflow: auto; width: 600px; height: 400px; font-family: Courier; font-size: 8pt;"><br /><pre># LunarLander2d.py<br /># Copyright Warren Sande, 2011<br /><br /># Based on LunarLander, Copyright Warren Sande, 2009<br /># Released under MIT license http://www.opensource.org/licenses/mit-license.php<br /><br /><br /># LunarLander 2D<br /># simulation game of landing a spacecraft<br />"""<br />The original LunarLander in "Hello World! Computer Programming<br />for Kids and Other Beginners"<br />was a very simple 1-D (y-axis, vertical motion only)<br />version of Lunar Lander, just to demonstrate a simple<br />gravity simulaiton using Pygame.<br /><br />LunarLander 2D adds the x-axis (sideways motion).<br />You can now rotate the lander using<br />the right/left arrow keys, more like<br />the original arcade version.<br />It also changes the thrust control from a<br />mouse-based (dragging the slider) to key-based<br />(press/hold the spacebar).<br /><br />Instead of the moonsurface image,<br />it uses a simple landing pad rectangle.<br /><br />"""<br /><br /># initialize - get everything ready<br />import pygame, sys<br />from math import *<br />pygame.init()<br />#wider screen than LunarLander, since we have sideways motion<br />screen = pygame.display.set_mode([800,600])<br />screen.fill([0, 0, 0])<br />ground = 540 #landing pad is ay y = 540<br />start = 90 # starting location 90 pixels from top of window<br />clock = pygame.time.Clock()<br />ship_mass = 5000.0<br />fuel = 5000.0<br />fps = 30 #default<br />x_loc = 20 # x-location in meters = dist from center of landing pad<br />y_loc = 40 # y-location in meters = height above the landing pad<br /><br />x_offset = 40 # offsets so that when ship location is (0,0), ship is<br />y_offset = -108 # just touching landing pad, and centered.<br /><br />x_speed = 2000.0 #pixels/frame<br />y_speed = -800.0<br /><br />x_velocity = x_speed/(10.0*fps) #m/s<br />y_velocity = y_speed/(10.0*fps)<br /><br />gravity = 1.5<br />thrust = 0<br />delta_v = 0<br />scale = 10 #scale factor from pixels to meters<br />throttle_down = False<br />left_down = False<br />right_down = False<br />#held_down = False<br />count = 0<br />x_pos = 0<br />y_pos = 0<br /><br />"""<br />x_pos, y_pos in pixels - (0,0) is top left<br />x_loc, y_loc in meters - (0,0) is center of landing pad<br /><br />x_speed, y_speed in pixels per frame.<br />x_velocity, y_velocity in m/s<br /><br />scale factor = 10 (10 pixels = 1 meter)<br /><br />pos (pixels) to loc (meters) is scaled by: scaleFactor (meters/pixel)<br />speed (pixels/frame) to velocity (m/s) is scaled by:<br />ScaleFactor * FPS (Frames Per Second)<br /><br />"""<br /><br /><br /># sprite for the ship<br />class ShipClass(pygame.sprite.Sprite):<br /> def __init__(self, image_file, position):<br /> <br /> pygame.sprite.Sprite.__init__(self)<br /> self.imageMaster = pygame.image.load(image_file)<br /> self.image = self.imageMaster<br /> self.rect = self.image.get_rect()<br /> self.position = position<br /> self.rect.centerx, self.rect.centery = self.position<br /> self.angle = 0<br /><br /> def update(self):<br /> self.rect.centerx, self.rect.centery = self.position<br /> oldCenter = self.rect.center<br /> self.image = pygame.transform.rotate(self.imageMaster, self.angle)<br /> self.rect = self.image.get_rect()<br /> self.rect.center = oldCenter<br /><br /><br /># calcualte position, motion, acceleration, fuel<br />def calculate_velocity():<br /> global ship, thrust, fuel, x_velocity, y_velocity, x_loc, y_loc<br /> global tot_velocity, scale, x_pos, y_pos, x_speed, y_speed<br /><br /> delta_t = 1/fps<br /> <br /> #Calculate thrust based on spacebar being held down<br /> if throttle_down:<br /> thrust = thrust + 100<br /> if thrust > 1000:<br /> thrust = 1000<br /> else:<br /> if thrust > 0:<br /> thrust = thrust - 200<br /> if thrust < 0:<br /> thrust = 0 <br /> fuel -= thrust /(10 * fps) # use up fuel<br /> if fuel < 0: fuel = 0.0<br /> if fuel < 0.1: thrust = 0.0<br /> ythrust = thrust * cos(ship.angle*(pi/180))<br /> xthrust = thrust * sin(ship.angle*(pi/180))<br /> y_delta_v = delta_t * (-gravity + 50 * ythrust / (ship_mass + fuel))<br /> y_velocity = y_velocity + y_delta_v<br /> x_delta_v = delta_t * (-50 * xthrust/(ship_mass + fuel)) <br /> x_velocity = x_velocity + x_delta_v<br /> x_speed = x_velocity * 10.0/fps #speed in pixels/frame, velocity in m/s<br /> y_speed = y_velocity * 10.0/fps<br /> y_loc = y_loc + y_velocity/fps # loc in meters, velocity in m/s<br /> x_loc = x_loc - x_velocity/fps<br /> tot_velocity = sqrt(x_velocity**2 + y_velocity**2)<br /> ship.position[0] = x_pos = screen.get_width()/2 - (scale * x_loc) + x_offset<br /> ship.position[1] = y_pos = screen.get_height() - (scale * y_loc) + y_offset<br /><br /><br /> if right_down:<br /> ship.angle = ship.angle - 2<br /> if left_down:<br /> ship.angle = ship.angle + 2 <br /> ship.update()<br /><br /><br /><br /># display the text with the speed, height, etc. <br />def display_stats():<br /> vv_str = "vertical speed: %.1f m/s" % y_velocity # in m/s<br /> hv_str = "horizontal speed %.1f m/s" % x_velocity # in m/s<br /> tv_str = "Total Velocity %.1f m/s" % tot_velocity # in m/s<br /> h_str = "height: %.1f m" % y_loc #in meters<br /> x_str = "position: %.1f m" % x_loc<br /> ang_str = "Angle: %.1f" % ship.angle<br /> t_str = "thrust: %i kg" % thrust<br /> a_str = "acceleration: %.1f m/s/s" % (delta_v * fps)<br /> f_str = "fuel: %i" % fuel<br /><br /> vv_font = pygame.font.Font(None, 26) #vertical speed<br /> vv_surf = vv_font.render(vv_str, 1, (255, 255, 255))<br /> screen.blit(vv_surf, [10, 50])<br /><br /> hv_font = pygame.font.Font(None, 26) #horizontal speed<br /> hv_surf = hv_font.render(hv_str, 1, (255, 255, 255))<br /> screen.blit(hv_surf, [10, 70])<br /><br /> hv_font = pygame.font.Font(None, 26) #horizontal speed<br /> hv_surf = hv_font.render(hv_str, 1, (255, 255, 255))<br /> screen.blit(hv_surf, [10, 90])<br /><br /> h_font = pygame.font.Font(None, 26) #y-location (height)<br /> h_surf = h_font.render(h_str, 1, (255, 255, 255))<br /> screen.blit(h_surf, [10, 120])<br /><br /> x_font = pygame.font.Font(None, 26) #x_location<br /> x_surf = x_font.render(x_str, 1, (255, 255, 255))<br /> screen.blit(x_surf, [10, 150])<br /><br /> ang_font = pygame.font.Font(None, 26) #angle<br /> ang_surf = ang_font.render(ang_str, 1, (255, 255, 255))<br /> screen.blit(ang_surf, [10, 180])<br /><br /> t_font = pygame.font.Font(None, 26) #thrust<br /> t_surf = t_font.render(t_str, 1, (255, 255, 255))<br /> screen.blit(t_surf, [10, 210])<br /><br /> a_font = pygame.font.Font(None, 26) #acceleration<br /> a_surf = a_font.render(a_str, 1, (255, 255, 255))<br /> screen.blit(a_surf, [10, 240])<br /><br /> f_font = pygame.font.Font(None, 26) #fuel<br /> f_surf = f_font.render(f_str, 1, (255, 255, 255))<br /> screen.blit(f_surf, [60, 330])<br /><br /># display the ship's flames - size depends on the amount of thrust <br />def display_flames():<br /> fsize = thrust / 30 #flame size<br /> # for rotation, need to do some trig to draw the flame triangles<br /> # in the correct orientation<br /> # points a-f are the 6 vertices of the 2 flame triangles <br /><br /> # calcualte polar coordinates of un-rotated flames <br /> a_len = sqrt(43*43 + 17*17)<br /> b_len = sqrt( (43+fsize)*(43+fsize) + 13*13)<br /> c_len = sqrt(43*43 + 9*9)<br /> d_len = c_len<br /> e_len = b_len<br /> f_len = a_len<br /> a_ang_orig = atan2(-17.0,-43.0)<br /> b_ang_orig = atan2(-13.0,(-43-fsize))<br /> c_ang_orig = atan2(-9.0,-43.0)<br /> d_ang_orig = atan2(9.0,-43.0)<br /> e_ang_orig = atan2(13.0,(-43.0-fsize))<br /> f_ang_orig = atan2(17.0,-43.0)<br /><br /> # rotate flame by same angle as ship rotation<br /> a_ang_rot = a_ang_orig + (270-ship.angle)*(pi/180)<br /> b_ang_rot = b_ang_orig + (270-ship.angle)*(pi/180)<br /> c_ang_rot = c_ang_orig + (270-ship.angle)*(pi/180)<br /> d_ang_rot = d_ang_orig + (270-ship.angle)*(pi/180)<br /> e_ang_rot = e_ang_orig + (270-ship.angle)*(pi/180)<br /> f_ang_rot = f_ang_orig + (270-ship.angle)*(pi/180)<br /><br /> # calculate x-y coordinates of rotated flames <br /> ax = int(a_len * cos(a_ang_rot))<br /> ay = int(a_len * sin(a_ang_rot))<br /> bx = int(b_len * cos(b_ang_rot))<br /> by = int(b_len * sin(b_ang_rot))<br /> cx = int(c_len * cos(c_ang_rot))<br /> cy = int(c_len * sin(c_ang_rot))<br /> dx = int(d_len * cos(d_ang_rot))<br /> dy = int(d_len * sin(d_ang_rot))<br /> ex = int(e_len * cos(e_ang_rot))<br /> ey = int(e_len * sin(e_ang_rot))<br /> fx = int(f_len * cos(f_ang_rot))<br /> fy = int(f_len * sin(f_ang_rot))<br /><br /> #draw the flames<br /> pygame.draw.polygon(screen, [255, 109, 14],<br /> [(x_pos + ax, y_pos + ay),<br /> (x_pos + bx, y_pos + by),<br /> (x_pos + cx, y_pos + cy)], 0)<br /> pygame.draw.polygon(screen, [255, 109, 14],<br /> [(x_pos + dx, y_pos + dy),<br /> (x_pos + ex, y_pos + ey),<br /> (x_pos + fx, y_pos + fy)], 0)<br /><br /># display final stats when the game is over<br />def display_final():<br /> global x_velocity, y_velocity, tot_velocity, ship #, fuelbar<br /> final1 = "Game over"<br /> final2 = "You landed at:"<br /> final3 = "%.1f m/s horizontal" % x_velocity<br /> final4 = "%.1f m/s vertical" % y_velocity<br /> final5 = "%.1f m/s Total" % tot_velocity<br /> final6 = "%.1f degrees" % ship.angle<br /> screen.fill([0, 0, 0])<br /> pygame.draw.rect(screen, [0, 0, 255], [80, 350, 24, 100], 2)<br /> pygame.draw.rect(screen, [0,255,0], [84,448-fuelbar,18, fuelbar], 0)<br /> drawTerrain()<br /> screen.blit(ship.image, ship.rect)<br /><br /> if (abs(tot_velocity) < 2 and abs(ship.angle) < 5):<br /> final7 = "Nice landing!"<br /> final8 = "I hear NASA is hiring!"<br /> elif (abs(tot_velocity) < 55 and abs(ship.angle < 10)):<br /> final7 = "Ouch! A bit rough, but you survived."<br /> final8 = "You'll do better next time."<br /> else:<br /> final7 = "Yikes! You crashed a 30 Billion dollar ship."<br /> final8 = "How are you getting home?"<br /> pygame.draw.rect(screen, [0, 0, 0], [5, 5, 350, 280],0)<br /> f1_font = pygame.font.Font(None, 70)<br /> f1_surf = f1_font.render(final1, 1, (255, 255, 255))<br /> screen.blit(f1_surf, [20, 50])<br /> f2_font = pygame.font.Font(None, 40)<br /> f2_surf = f2_font.render(final2, 1, (255, 255, 255))<br /> screen.blit(f2_surf, [20, 110])<br /> f3_font = pygame.font.Font(None, 26)<br /> f3_surf = f3_font.render(final3, 1, (255, 255, 255))<br /> screen.blit(f3_surf, [20, 150])<br /> f4_font = pygame.font.Font(None, 26)<br /> f4_surf = f4_font.render(final4, 1, (255, 255, 255))<br /> screen.blit(f4_surf, [200, 150])<br /> f5_font = pygame.font.Font(None, 26)<br /> f5_surf = f5_font.render(final5, 1, (255, 255, 255))<br /> screen.blit(f5_surf, [380, 150])<br /> f6_font = pygame.font.Font(None, 26)<br /> f6_surf = f6_font.render(final6, 1, (255, 255, 255))<br /> screen.blit(f6_surf, [20, 180])<br /> f7_font = pygame.font.Font(None, 26)<br /> f7_surf = f7_font.render(final7, 1, (255, 255, 255))<br /> screen.blit(f7_surf, [20, 210])<br /> f8_font = pygame.font.Font(None, 26)<br /> f8_surf = f8_font.render(final8, 1, (255, 255, 255))<br /> screen.blit(f8_surf, [20, 240])<br /> screen.blit(inst1_surf, [50, 550])<br /> screen.blit(inst2_surf, [20, 575])<br /> screen.blit(inst3_surf, [50, 600])<br /> pygame.display.flip()<br /><br /><br /># draw the landing pad.<br /># note: This could be made more complex, but just a<br /># simple landing pad for now.<br />def drawTerrain():<br /> pygame.draw.rect(screen, [180, 180, 180], [420, 535, 70, 5],0) <br /><br /># make an instance of the ship sprite<br />ship = ShipClass('lunarlander.png', [500, 230])<br /><br /># main loop<br />while True:<br /> clock.tick(30)<br /> fps = clock.get_fps()<br /> if fps < 1: fps = 30<br /> count += 1<br /> if y_loc > 0.01: <br /> calculate_velocity()<br /> screen.fill([0, 0, 0])<br /> display_stats()<br /> pygame.draw.rect(screen, [0, 0, 255], [80, 350, 24, 100], 2)<br /> fuelbar = 96 * fuel / 5000<br /> pygame.draw.rect(screen, [0,255,0], [84,448-fuelbar,18, fuelbar], 0)<br /> drawTerrain() <br /> display_flames() <br /> screen.blit(ship.image, ship.rect)<br /> instruct1 = "Land softly without running out of fuel"<br /> instruct2 = "Good landing: < 5 m/s Great landing: < 2m/s"<br /> instruct3 = "And you must be within 10 degrees of vertical"<br /> inst1_font = pygame.font.Font(None, 24)<br /> inst1_surf = inst1_font.render(instruct1, 1, (255, 255, 255))<br /> screen.blit(inst1_surf, [50, 550])<br /> inst2_font = pygame.font.Font(None, 24)<br /> inst2_surf = inst1_font.render(instruct2, 1, (255, 255, 255))<br /> screen.blit(inst2_surf, [20, 575])<br /> inst3_font = pygame.font.Font(None, 24)<br /> inst3_surf = inst3_font.render(instruct3, 1, (255, 255, 255))<br /> screen.blit(inst3_surf, [50, 600])<br /> pygame.display.flip()<br /><br /> else: #game over - print final score<br /> display_final()<br /> <br /> for event in pygame.event.get():<br /> if event.type == pygame.QUIT:<br /> sys.exit()<br /> elif event.type == pygame.KEYDOWN:<br /> if event.key == pygame.K_SPACE:<br /> throttle_down = True<br /> if event.key == pygame.K_RIGHT:<br /> right_down = True<br /> if event.key == pygame.K_LEFT:<br /> left_down = True<br /> elif event.type == pygame.KEYUP:<br /> if event.key == pygame.K_SPACE:<br /> throttle_down = False<br /> if event.key == pygame.K_RIGHT:<br /> right_down = False<br /> if event.key == pygame.K_LEFT:<br /> left_down = False<br /><br /></pre><br /></div>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com1tag:blogger.com,1999:blog-614880431683631954.post-75438339691709643162011-03-14T12:16:00.000-07:002012-08-13T11:56:59.460-07:00Hello World! Chinese TranslationA few days ago we received a few copies of the Chinese translation of "Hello World". Here's what the cover looks like:<br />
<div>
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvbh_WVcMKiWaubBWkJeqJAUcrdZBEYKZAdy4FwLovFgoSEQ6nX0o400ywLHjGYhS8j8solnbVxu9qa51KxOg47G9hGmXCk8M-BiZ5G6rwrGaLQQM4b-LIFXyLRjI87Gn7B6CTGkj09OU/s1600/ChineseCoverMedium.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5584017475627350706" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvbh_WVcMKiWaubBWkJeqJAUcrdZBEYKZAdy4FwLovFgoSEQ6nX0o400ywLHjGYhS8j8solnbVxu9qa51KxOg47G9hGmXCk8M-BiZ5G6rwrGaLQQM4b-LIFXyLRjI87Gn7B6CTGkj09OU/s320/ChineseCoverMedium.jpg" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 220px;" /></a><br />
<div style="text-align: center;">
<br />
<div style="text-align: left;">
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:<br />
<br />
<a href="http://www.turingbook.com/Books/ShowBook-629.aspx">http://www.turingbook.com/Books/ShowBook-629.aspx</a><br />
<br />
<br /></div>
</div>
</div>
wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com3tag:blogger.com,1999:blog-614880431683631954.post-46174920577830733572011-02-27T11:59:00.000-08:002011-02-27T12:26:04.613-08:00What to do if you're having problems.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.<div><ol><li><b>Proper version of Python and all required modules.</b> Did you use our book's installer to get Python? If not, get the installer <a href="http://www.manning.com/sande/Installation_Instructions.html">here</a> and follow the instructions. </li><li><b>Indentation.</b> Make sure spacing is correct. This is very important in Python.</li><li><b>Check for typos.</b> 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.</li></ol><div>If you still can't figure it out, leave a comment on our blog, post a question on our <a href="http://www.manning-sandbox.com/forum.jspa?forumID=410">Author Forum</a>, or e-mail us at <a href="mailto:cp4khelp@yahoo.com">cp4khelp@yahoo.com</a> . We do our best to get back to you within 48 hours.</div></div><div><br /></div><div>--Carter</div>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com0tag:blogger.com,1999:blog-614880431683631954.post-57513149528175416742010-09-23T16:11:00.000-07:002010-11-05T21:50:18.615-07:00Cool stuff for MacHey guys,<br /><br />Recently, I got a Mac. This means I'll be able to help a lot more with Mac problems on <a href="http://www.manning-sandbox.com/forum.jspa?forumID=410">our author forums</a> 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 <span class="Apple-style-span" style="font-family:'courier new';">import</span><span class="blsp-spelling-error" id="SPELLING_ERROR_0">ing</span> <span class="Apple-style-span" style="font-family:'courier new';"><span class="blsp-spelling-error" id="SPELLING_ERROR_1">os</span></span><span class="Apple-style-span" style="font-family:'times new roman';">. OS is a module that lets you interact with your computer's operating system. Then, type the following:</span><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="blsp-spelling-error" id="SPELLING_ERROR_2">os</span>.system("say Hello World!")</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">This will send a command to Mac OS telling it to, well, say, "Hello World!" You can put whatever you want after </span><span class="Apple-style-span" style="font-family:'courier new';">say</span><span class="Apple-style-span" style="font-family:'times new roman';">. 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:</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';">import <span class="blsp-spelling-error" id="SPELLING_ERROR_3">os</span></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="blsp-spelling-error" id="SPELLING_ERROR_4">os</span>.system("say Whats your name?") <br />#For some reason, apostrophes don't work.</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><br />name = raw_input("What's your name?")<br /># It's good to put it on the screen as well,<br /># in case users don't have their speakers on.<br /><br /></span></div><div><span class="Apple-style-span" style="font-family:'courier new';">print "Hi, "+name+", hows it going?"</span></div><div><span class="Apple-style-span" style="font-family:'courier new';">os.system("say </span><span class="Apple-style-span" style="font-family:'courier new';">Hi, "+name+", hows it going?")</span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">I hope this brings a whole new level of interaction to all your future programs!</span></div><div><span class="Apple-style-span" style="font-family:'times new roman';"><br /></span></div><div><span class="Apple-style-span" style="font-family:'times new roman';">Carter Sande</span></div>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com5tag:blogger.com,1999:blog-614880431683631954.post-36267870630418491632010-06-29T22:16:00.000-07:002010-06-29T22:40:59.914-07:00Carter Teaches Random<object height="385" width="480"><param name="movie" value="http://www.youtube.com/v/_C6_QjRgCPE&hl=en_US&fs=1&rel=0"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/_C6_QjRgCPE&hl=en_US&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="385" width="480"></embed></object><br /><br />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:<br /><a href="http://young-programmers.blogspot.com/2010/06/randomness-in-python-lesson-by-carter.html">http://young-programmers.blogspot.com/2010/06/randomness-in-python-lesson-by-carter.html</a>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com0tag:blogger.com,1999:blog-614880431683631954.post-31347312590518985392010-06-07T20:14:00.000-07:002010-06-07T20:21:18.357-07:00Carter's VPython PodcastA couple of weeks ago, Carter did a podcast on VPython (Visual Python), a module to create 3D graphics. You can see it here:<br /><br /><object height="385" width="480"><param name="movie" value="http://www.youtube.com/v/ydrNETZkfkw&hl=en_US&fs=1&color1=0x234900&color2=0x4e9e00"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/ydrNETZkfkw&hl=en_US&fs=1&color1=0x234900&color2=0x4e9e00" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="385" width="480"></embed></object><br /><br /><br />For our next podcast, Carter will be answering questions from readers. So, please post any questions you have about Python or related modules in our Author Forum, at:<br /><a href="http://www.manning-sandbox.com/thread.jspa?threadID=38048&stqc=true">http://www.manning-sandbox.com/thread.jspa?threadID=38048&stqc=true</a><br /><br /><br />Warren and Carterwsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com1tag:blogger.com,1999:blog-614880431683631954.post-81475446247701310452010-03-11T21:20:00.000-08:002010-03-11T21:45:23.644-08:00Passing arguments as a listIn the Author Forum on the Manning page for the book, someone asked about passing arguments to a function as a list. Since posting code on that forum doesn't work well, I thought I would post the answer here.<br /><br />If you are passing a number of arguments to a function, you could pass them as individual arguments, like this:<br /><span style="font-family:courier new;"><br /><pre style="background: rgb(220, 220, 220) none repeat scroll 0% 0%; color: rgb(0, 0, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><br />def printMyLuckyNumbers(num1, num2, num3, num4, num5):<br /> print "Here are your lucky numbers:"<br /> print num1, num2, num3, num4, num5<br /><br /></pre></span><br /><span style="font-family:georgia;"><br />Then you would call the function like this: </span><br /><span style="font-family:courier new;"><br /><pre style="background: rgb(220, 220, 220) none repeat scroll 0% 0%; color: rgb(0, 0, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><br />printMyLuckyNumbers(3, 7, 10, 14, 27)<br /><br /></pre></span><br /><span style="font-family:georgia;"><br />But that has a couple of disadvantages. First, if there are a lot of arguments, it gets messy to type all the variable names. Second, you might not know ahead of time how many arguments you want to pass.<br /><br />So, another way, that solves both those problems, is to pass a list of arguments instead, like this:</span><br /><span style="font-family:courier new;"><br /><pre style="background: rgb(220, 220, 220) none repeat scroll 0% 0%; color: rgb(0, 0, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><br />def printMyLuckyNumbers(myNums):<br /> print "Your lucky numbers are:"<br /> for num in myNums:<br /> print num,<br /><br /></pre></span><br /><span style="font-family:georgia;"><br />Then you would call the function like this: </span><br /><span style="font-family:courier new;"><br /><pre style="background: rgb(220, 220, 220) none repeat scroll 0% 0%; color: rgb(0, 0, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><br />myLuckyNumbers = [3, 7, 10, 14, 27]<br />printMyLuckyNumbers(myLuckyNumbers)<br /><br /></pre></span><br /><span style="font-family:georgia;"><br />In the first example, you are passing 5 separate arguments. In the second example, you are passing a single list. That list happens to have 5 items, in this example. But it would work with any number of items. For example, this would work just fine when calling the second version of the function: </span><br /><span style="font-family:courier new;"><br /><pre style="background: rgb(220, 220, 220) none repeat scroll 0% 0%; color: rgb(0, 0, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><br />myLuckyNums = [2, 3, 5, 7, 10, 27, 32, 45]<br />printMyLuckyNumbers(myLuckyNums)<br /><br /></pre></span><br /><span style="font-family:georgia;"><br />These are very simple examples. You can pass things more complicated than lists. You can pass nested lists (lists of lists, or two-dimensional lists). You can pass objects, which can contain any data structure you care to define. You can pass lists of objects or objects containing lists (or dictionaries, or any other Python data type).</span>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com10tag:blogger.com,1999:blog-614880431683631954.post-31629297187921421332010-01-14T21:34:00.000-08:002010-01-14T21:47:23.675-08:00Hello World! on HanselMinutesCarter and Warren recently appeared on the HanselMinutes podcast. Hanselminutes is a weekly audio show with web technology blogger Scott Hanselman.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjyXsUEPykp1enOdLadFXaMfY2e03ZC53M684DGK5cJ1NkDfaVZ94ZpnwIImY13fkkT7WeJAAmEUjHwSNOkyrGMOVhDzjjVX94YwBlhu1PJklZAluOi1fVWm7BFvPOVyLbsbp4hcPHkzA/s1600-h/hanselminutes.JPG"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px; height: 58px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjyXsUEPykp1enOdLadFXaMfY2e03ZC53M684DGK5cJ1NkDfaVZ94ZpnwIImY13fkkT7WeJAAmEUjHwSNOkyrGMOVhDzjjVX94YwBlhu1PJklZAluOi1fVWm7BFvPOVyLbsbp4hcPHkzA/s200/hanselminutes.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5426839033429676066" /></a><br />You can <a href="http://www.hanselminutes.com/default.aspx?showID=212">find the podcast here</a>.wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com5tag:blogger.com,1999:blog-614880431683631954.post-65142800172709021962010-01-02T20:36:00.001-08:002011-03-14T12:38:34.315-07:00Hello World! German TranslationWe recently discovered that there is a German translation of "Hello World!" We found it on the <a href="http://www.amazon.co.uk/Hello-World-Programmieren-andere-Anf%C3%A4nger/dp/3446421440/ref=sr_1_2?ie=UTF8&s=books&qid=1263487096&sr=8-2">amazon.co.uk</a> site.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqTmvu5OP-IhoxSTOTnoaXJIYvFD_2NFdoNHmodQ6nAWQomrkMrDVUpDBQ-9zeBOc6JIpxNHuCZuYrWNlVkY6FpJmyj109dXEw5NdIDf8aqbwHIEWJuDcpupsj7lEKTY__jAtmnKhC-mI/s1600-h/helloworldgerman.JPG"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 234px; height: 320px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqTmvu5OP-IhoxSTOTnoaXJIYvFD_2NFdoNHmodQ6nAWQomrkMrDVUpDBQ-9zeBOc6JIpxNHuCZuYrWNlVkY6FpJmyj109dXEw5NdIDf8aqbwHIEWJuDcpupsj7lEKTY__jAtmnKhC-mI/s320/helloworldgerman.JPG" alt="" id="BLOGGER_PHOTO_ID_5426636936056078274" border="0" /></a><br /><br /><br />You can see some sample chapters here:<br /><br /><a href="http://files.hanser.de/hanser/docs/20091105_29115165758-68_978-3-446-42144-8_Inhaltsverzeichnis.pdf">Table of Contents</a><br /><a href="http://files.hanser.de/hanser/docs/20091105_29115165937-86_978-3-446-42144-8_Vorwort.pdf">Preface</a><br /><a href="http://files.hanser.de/hanser/docs/20091105_29115165951-126_978-3-446-42144-8_Lesperobe.pdf">Chapter 1</a><br /><br />Oddly, our publisher, Manning, didn't tell us about the translation. We just stumbled across it ourselves. The publishing world sometimes works in strange and mysterious ways!wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com2tag:blogger.com,1999:blog-614880431683631954.post-31571281570144298452009-11-10T20:21:00.000-08:002010-01-14T08:35:45.063-08:00Carter Explains PythonCard on Young Programmer's PodcastA fellow named Dave Briccetti has a site dedicated to young programmers. Part of that site is the <a href="http://young-programmers.blogspot.com/">Young Programmers Podcast</a>.<br /><br />Carter recently did a Podcast on PythonCard for the Young Programmer's Podcast. Dave tells us it's one of the most popular items on the podcast!<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJwogiZU97ymjk0JowzbAt6UtHkgFW0tWpESuoU9GTHn51C4brQfizuwkM0lur3UwKIKciHIDALuyi-hCUDBiaxyO-MKxtJgmBQpeUGAnFoyZygocQBk0z8nPKz516b3vd-SJUh2wl6eU/s1600-h/YPPscreenshot.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 400px; height: 193px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJwogiZU97ymjk0JowzbAt6UtHkgFW0tWpESuoU9GTHn51C4brQfizuwkM0lur3UwKIKciHIDALuyi-hCUDBiaxyO-MKxtJgmBQpeUGAnFoyZygocQBk0z8nPKz516b3vd-SJUh2wl6eU/s400/YPPscreenshot.jpg" alt="" id="BLOGGER_PHOTO_ID_5426633825252809442" border="0" /></a><br /><br /><br />You can <a href="http://young-programmers.blogspot.com/2009/11/carter-sande-presents-pythoncard.html">see it here</a>.wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com1tag:blogger.com,1999:blog-614880431683631954.post-4657553170244193602009-06-30T23:10:00.001-07:002009-07-04T14:08:57.576-07:00Carter and Warren on TV<a style="" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://watch.ctv.ca/news/clip186877#clip186877"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 270px; height: 203px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQcbAWTTDznJ-Bnmvuu7eFzR6OnsrNw3eXJtrJAdIvhX0fEnCMdrT5LiggvB1M1kaVeOLiSPHewiOXH8N1viciQREwJHXaZnMUj0w06a7nHY-kYF5DwyWu_PNGX82hAuKUsfGoYcAyx-g/s400/tv+interview+screenshot.JPG" alt="" id="BLOGGER_PHOTO_ID_5353371066803895986" border="0" /></a><br />We hosted a Book Launch party on June 24, 2009.<br /><br />That day, we also did an interview on the Ottawa CTV affiliate, CJOH, with anchor Carol-Anne Meehan.<br /><br /><br />It ran on their 6:00 news. You can see it here:<br /><span><a rel="nofollow" target="_blank" href="http://watch.ctv.ca/news/clip186877#clip186877"><span style="color: rgb(0, 0, 255);">http://watch.ctv.ca/news/clip186877#clip186877</span></a><br /><br />You can also read the <a href="http://www.emckanata.ca/20090703/news/Father%2C+son+pen+book+on+computer+programming">article</a> EMC newspaper wrote about us. Reporter Sabine Gibbins talked to Carter, Warren, and illustrator Martin Murtonen the day of the launch.<br /><br />We also met Martin for the first time that day. All our work together on the book had been done by e-mail and phone, even though we live in the same city!<br /><br /></span>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com6tag:blogger.com,1999:blog-614880431683631954.post-57253831690842112242009-06-29T16:41:00.000-07:002010-01-22T08:02:47.825-08:00Connect the Dots 2In Chapter 16 of Hello World, we presented a Connect the Dots program that would create a "mystery picture". (This is Listing 16.10.)<br /><br />One of our readers created another version that draws the dots and lines one at a time, instead of all at once. So it's kind of an "animated" version of the Connect the Dots program.<br /><br />Once again, we want you to type this one in, not just cut-and-paste it from the download site. Here's the code for the animated version:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqgdDV3W_PMPkZtuNKEeuPXqXNQ5_D_mmgt1WgwwFuTuQSNF8b86tKpysmSpICZtcDJyAHyxpyCO3H3xzNaIwQliFUdHVQTq4HsMiCJ91j8Uwteyn499MVItpbqwonQSFfl4wZn3vXqoI/s1600-h/connect_dots2.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 625px; height: 521px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqgdDV3W_PMPkZtuNKEeuPXqXNQ5_D_mmgt1WgwwFuTuQSNF8b86tKpysmSpICZtcDJyAHyxpyCO3H3xzNaIwQliFUdHVQTq4HsMiCJ91j8Uwteyn499MVItpbqwonQSFfl4wZn3vXqoI/s400/connect_dots2.bmp" alt="" id="BLOGGER_PHOTO_ID_5397060732878214034" border="0" /><br /></a><br />This code might look a little fuzzy, and some of the lines are cut off. That's because it's an image of the code, and that's the way Blogger displays the image. If you click on the code, you'll get a much more clear version with nothing cut off. But it's still an image, so you can't copy-and-paste the code.<br /><br />As we mentioned in the book, the <a href="http://www.manning.com/sande/sourcecode/All_Files_By_Chapter/hw_ch16_code/dots_list.txt">list of dot coordinates</a> is available from the download site, so you don't have to type in all those numbers. (Just copy-and paste them from your browser to the code editor.) But you do have to type in the rest of the program if you want to see the picture.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqgdDV3W_PMPkZtuNKEeuPXqXNQ5_D_mmgt1WgwwFuTuQSNF8b86tKpysmSpICZtcDJyAHyxpyCO3H3xzNaIwQliFUdHVQTq4HsMiCJ91j8Uwteyn499MVItpbqwonQSFfl4wZn3vXqoI/s1600-h/connect_dots2.bmp"><br /></a>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com3tag:blogger.com,1999:blog-614880431683631954.post-29221745987134274022009-04-20T13:50:00.000-07:002010-06-29T22:41:25.353-07:00Book in handThe printed books are finally here!<br /><br />We have been waiting a long time, and we finally have the printed books in our hands. It's pretty exciting to actually see it, hold it, and turn the pages.<br /><br />There was a little glitch with the printing. Due to some kind of error at the printer, some of graphics didn't print properly in the first printing. Our Production Manager at Manning, Mary Piergies, told us this was the first time this happened in the 13 years she has been working there, and she has produced hundreds of titles. So, of course, it had to happen to our book! (What are the odds...?)<br /><br />But the corrected copies have now been printed. Anyone who received one of the first printings will get a corrected copy. (None of them went out to retail stores or Amazon. Some went out to people who ordered from the Manning web site.) You can make sure you have the corrected copy if you look on the copyright page (the second page inside the front cover). Near the bottom there is the ISBN number. If it is the corrected version, it says "Second corrected printing" right above the ISBN number. Any printing after that is also fine (third, fourth, etc.).<br /><br />The books should be on their way to retailers now, both online and "bricks and mortar" stores. You can already order it directly form Manning using <a href="http://www.manning.com/affiliate/idevaffiliate.php?id=1070_149">this link</a>.wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com8tag:blogger.com,1999:blog-614880431683631954.post-42106732284134677812009-04-06T22:40:00.000-07:002010-06-29T22:42:13.791-07:00ReviewsWhen we set out to write a book, we had some goals and a vision for how it would turn out. Getting the book written and published was a long and winding road. (It felt, really, really, excruciatingly long at times). So, when we got to the end of it and actually had a book in our hands, we wondered if those initial goals and vision made it through to the end result. Happily, we feel they did. But of course we want to know what others think of it, too. Do kids, parents, teachers, and other readers think the book is useful, readable, and fun?<br /><br />We've started getting some reviews of the book, and it is very gratifying to see that others are noticing and pointing out the very qualities that we tried hardest to include: fun and readable (but not condescending), well organized, suitable for use in schools and at home.<br /><br />Here's what some reviewers are saying about the book:<br /><br /><br /><blockquote> Colin D. Sulin (on amazon.com):<br />I'm an IT veteran with nearly 25 years of programming experience in a variety of languages and technologies. This book is really one of the best that I have come across. I'm teaching my girls and this book is just perfect for the task. I'm not a Python programmer, but this book is the best thing you can get for getting kids going in computers. I highly recommend it.<br /></blockquote><br /><br /><blockquote><a href="http://baoilleach.blogspot.com/2009/03/review-of-hello-world-computer.html">Noel O'Blog</a>:<br />I think this is a great book that fills a real niche. ... What's amazing is that it has set its sights so high, and yet manages to meet its goals. I think it would be great to see this book promoted as a way of teaching programming in primary schools. In the meanwhile if you know any 12+ kids interested in computers, give them an opportunity to develop a fascinating hobby and get them this book.<br /></blockquote><br /><br /><blockquote>JR Peck (on <a href="http://books.slashdot.org/story/09/07/13/1349203/Hello-World">Slashdot</a>)<br />The book is formatted with lots of visuals and fly-outs that give information on how computers operate and how programming languages deal with information processing. My daughter and I have already had interesting discussions on subjects like integers and floats. An example that draws a sine wave led to a great teachable moment about amplitude and wave length. Then there is the constant need for approaching problem solving in a structured manner using logic. I think that taking on programming brings a wide number of benefits.<br /></blockquote><br /><br /><blockquote><a href="http://bucket-o-cool.blogspot.com/2009/04/python-taming.html">Bucket-O-Cool</a>:<br />Hello World! Computer Programming for Kids and Other Beginners is a clear and easy-to-digest voyage through the beginnings of programming with Python. ... By having a junior author involved in the learning process, the reader can quickly identify with the questions being asked to either reinforce the concept that they have learned, or if required, cling to it like a life preserver until they come to a better understanding. It’s a good writing strategy that not only supports an even paced read and lesson, but makes the task at hand genuinely more enjoyable.</blockquote><br /><br /><blockquote>Dan Appleman (<a href="http://www.examiner.com/x-1652-Gadgets-Examiner%7Ey2009m4d3-Hello-World--computer-programming-for-kids--beginners">Gadgets Examiner</a>):<br />"Hello World” is easy to read, well written and logically organized. ... In an unusual twist, the authors chose to use Python as their computer language. In this they made an outstanding decision. ... Beginners learn best with a kind of language called an interpreter – that allows you to experiment interactively, and Python is a fine choice. Plus the Python language is similar enough to other languages so that a kid who learns it will be able to move to others if necessary. The programming concepts that are taught in the book are easily transferrable to other languages.<br /><br />The book also has a nice selection of sample programs, with an emphasis on games, but with enough variety that a broad set of concepts can be covered. And the games include graphics – which adds to the appeal.... So this is one book that I’d encourage you not just to buy for your kids, but to read and work on with them.<br /></blockquote><br /><br /><blockquote><a href="http://www.cuberick.com/2009/01/programming-for-kids.html">Cuberick.com</a>:<br />These days a search for "programming for kids" on Amazon wouldn't return any interesting results, <i>until now</i>. A new book called "Hello World! Computer Programming for Kids and Other Beginners" has just come out. It is a book in the spirit of those old BASIC programming books. It covers the fundamentals of programming using the Python language and has game programs that you can get started with including a lunar lander game and a ski-free clone. If you want to learn programming or teach it to a kid, this is your book. Enjoy!<br /></blockquote><br /><br /><blockquote>David Brin:<br />Hello World! helps challenge young people to take on technology, making it fun, without dumbing-down the adventure.<br /></blockquote><br /><br /><blockquote>Sue Gee (<a href="http://www.i-programmer.info/bookreviews/14-other-languages/189-hello-world-computer-programming-for-kids-and-other-beginners-.html">I-programmer</a>):<br />I'm very pleased to discover this new book written by a father and son team to help make up for a very real deficiency in the educational system. Learning to program is a mind expanding experience so while the book has been written to appeal to a young audience it has a lot to offer all beginners. It adopts a logical approach and presents clear explanations backed up by well chosen examples. This book is a very good introduction to programming and can be recommended to anyone, young or old, who wants to start learning this vital and highly enjoyable skill.<br /></blockquote><br /><br /><blockquote>Steven Gilham (on <a href="http://www.amazon.co.uk/product-reviews/1933988495/ref=cm_cr_dp_all_summary?ie=UTF8&showViewpoints=1&sortBy=bySubmissionDateDescending">amazon.co.uk</a>)<br />Hello World! is a gentle and humorous introduction to the idea of programming, using Python, a language well suited to filling the niche that BASIC dialects did a generation ago. Even to a crusty and cynical old-timer, like myself, it makes entertaining reading -- not only is the writing style light and engaging, but you can nod sagely and think "Been there, done that" at all the "In the good old days" asides.<br /><br />Trying out on members of the target audience, it has proven a hit. In its catchy and absorbing manner, it explains the fundamentals (the simple things like variable names being, well, just names) clearly and the exercises concentrate on making fun things happen sooner rather than later. The infectious enthusiasm of the author even managed to hook my non-programmer wife, and get her trying out the examples.<br /></blockquote><br /><br /><p style="margin-left: 40px;"></p>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com0tag:blogger.com,1999:blog-614880431683631954.post-9633451031436159012009-04-06T22:29:00.000-07:002010-06-29T22:42:51.846-07:00IllustrationsIf you've looked at the book (or even just the cover), you might be wondering about the person who did all the wonderful illustrations. His name is Martin Murtonen. You can find out more about his work at <a href="http://www.ihorace.com/">his web site</a>.<br /><br />Although we worked very closely with Martin to get all the illustrations just right, we never met him, until our Book Launch party, even though we live in the same city! All our collaboration was by phone and e-mail.<br /><br />That's one of the things about modern communications, and computers in particular. There are many people who work together or are friends who have never met in person. In fact, we have never met any of the people who worked on our book - editors, typesetters, production staff, and so on (except for a few reviewers who we knew before we started). One day we hope to meet some of the people who made our book come to life!wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com0tag:blogger.com,1999:blog-614880431683631954.post-21686554229649415652009-04-05T17:00:00.000-07:002009-07-14T10:45:59.856-07:00Python Help and Your Modules<span style="font-family:georgia;"><strong>Warren: </strong>In the book, we talked a bit about Python's help system. This is something that can give you help on using Python's built-in modules and functions as well as external modules and functions. But we didn't tell you how to add help to your own modules. In this post, we will. I'm going to let Carter take it from here.<br /><br /><strong>Carter: </strong>Hi! It's Carter here. This blog post is a guide to adding help to your Python modules. We will be starting with our TempConv module from Chapter 15:</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"># this is the file "my_module.py"<br /># we're going to use it in another program<br />def c_to_f(celsius):<br />fahrenheit = celsius * 9.0 / 5 + 32<br />return fahrenheit</pre></span><br /><span style="font-family:georgia;">First, let's see what help() brings up in Python:<br /></span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">>>> import my_module<br />Traceback (most recent call last):<br />File "<stdin>", line 1, in <module><br />ImportError: No module named my_module</module></stdin></pre></span><br /><br /><span style="font-family:georgia;">Oops! We forgot that Python can't find our module unless it's in a folder where python can find it. Navigate to this folder in Windows Explorer (or your favourite file browser):</span><br /><br /><span style="font-family:courier new;">C:\Python25\Lib\site-packages\<br /></span><br /><span style="font-family:georgia;">Among other things, you should see a Pygame folder, a PythonCard folder, and easygui.py (you might have to scroll down). Save my_module.py there, restart IDLE (or SPE, or Python Shell), and then try importing it again to make sure Python can find it.<br /><br />Now, let's see what help() brings:</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">>>> import my_module<br />>>> help(my_module)<br />Help on module my_module:<br /><br />NAME<br />my_module<br /><br />FILE<br />c:\python25\lib\site-packages\my_module.py<br /><br />DESCRIPTION<br /># this is the file "my_module.py"<br /># we're going to use it in another program<br /><br />FUNCTIONS<br />c_to_f(celsius)<br /># this is the file "my_module.py"<br /># we're going to use it in another program</pre></span><br /><span style="font-family:georgia;">Not very user-friendly. Let's try changing the comments.</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: Courier New; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"># My Module<br /># Our first module.<br />def c_to_f(celsius):<br /> #converts celsius to fahrenheit<br /> fahrenheit = celsius * 9.0 / 5 + 32<br /> return fahrenheit</pre><br /></span><br /><span style="font-family:georgia;">And now restart IDLE <strong>again </strong>(this is getting annoying...) and call help():</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">>>>import my_module<br />>>>help(my_module)<br />Help on module my_module:<br /><br />NAME<br />my_module<br />FILE<br />c:\python25\lib\site-packages\my_module.py<br />DESCRIPTION<br />#My Module<br />#Our first module.<br />FUNCTIONS<br />c_to_f(celsius)</pre></span><br /><span style="font-family:georgia;">Huh. Why didn't c_to_f's comment appear? The answer is that help() uses <strong>strings</strong>, but supports comments at the start of the program. Let's change my_module again:</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">"""My Module<br />Our first module."""<br /><br />def c_to_f(celsius):<br />"converts celsius to fahrenheit"<br />fahrenheit = celsius * 9.0 / 5 + 32<br />return fahrenheit</pre></span><br /><span style="font-family:georgia;">And now restart IDLE and use help again:</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">>>> import my_module<br />>>> help(my_module)<br />Help on module my_module:<br /><br />NAME<br />my_module<br />FILE<br />c:\python25\lib\site-packages\my_module.py<br /><br />DESCRIPTION<br />My Module<br />Our first module.<br /><br />FUNCTIONS<br />c_to_f(celsius)<br /> converts celsius to fahrenheit</pre><br /></span><br /><span style="font-family:georgia;">There, now that looks a lot better. Also, Python classes display similar help. Try typing this into my_module:</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">"""My Module<br />Our first module."""<br /><br />def c_to_f(celsius):<br />"converts celsius to fahrenheit"<br />fahrenheit = celsius * 9.0 / 5 + 32<br />return fahrenheit<br /><br />class SampleObject:<br />"Sample object"<br />def __init__(self, number):<br /> "Initializes object"<br /> self.number = number<br />def addOne(self):<br /> "Adds one to the number"<br /> self.number += 1</pre><br /></span><br /><span style="font-family:georgia;">And the help() is:</span><br /><span style="font-family:courier new;"><br /><pre style="BACKGROUND: rgb(170,170,170); COLOR: rgb(0,0,0); FONT-FAMILY: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial">>>> import my_module<br />>>> help(my_module)<br />Help on module my_module:<br /><br />NAME<br />my_module<br /><br />FILE<br />c:\python25\lib\site-packages\my_module.py<br /><br />DESCRIPTION<br />My Module<br />Our first module.<br /><br />CLASSES<br />SampleObject<br /><br />class SampleObject<br /> Sample object<br /><br /> Methods defined here:<br /><br /> __init__(self, number)<br /> Initializes object<br /> <br /> addOne(self)<br /> Adds one to the number<br /><br />FUNCTIONS<br />c_to_f(celsius)<br /> converts celsius to fahrenheit</pre><br /></span>One more thing: For help() to work correctly, your string also has to be on the first line of your program (or function, or class, or method), and be indented correctly.<br /><span style="font-family:georgia;">And that's how you can make your modules look great in help()!</span>wsandehttp://www.blogger.com/profile/14641505785796225627noreply@blogger.com2