Welcome to Computer Programming For Kids (CP4K)

Welcome to the Computer Programming for Kids blog! We are the co-authors of the book "Hello World! Computer Programming for Kids and Other Beginners", released in March 2009. The book is published by Manning Publications. Manning has a web site for the book, which is where you can download the software and other files related to the book. You can purchase it here, at the Manning web site. If you use this link to purchase the print book or e-book from the Manning web site, you can use the discount code aupromo40 at checkout to get a 40% discount. You can also get it through online retailers like Amazon, as well as in many retail locations such as Chapters in Canada and Barnes & Noble in the U.S. This blog is mostly about the book (for now), but anything related to computers and programming, particularly for kids and beginners, is fair game. We will post articles with extra material that didn't make it into the book, and reader feedback and suggestions are always welcome.
Showing posts with label speech. Show all posts
Showing posts with label speech. Show all posts

Thursday, September 23, 2010

Cool stuff for Mac

Hey guys,

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:

import os
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 Sande