It looks like you're using Python 2.7 instead of the version of Python the book's installer gives you (Python 2.5). Did you use the book's installer to get Python (and all the modules you need)?

Just a reminder, our new forum is http://helloworldbookblog.com/forum .
In the future, please post there because you can do things like post code there, and you'll typically get quicker responses.

Carter
Try deleting your savedata_vp.pkl. VirtualPet will generate a new save file, and we can see if the problem persists.

Also, we've moved our forum to http://helloworldbookblog.com/forum
You can do things like post code there, and there are several members there that can help you out.

Carter
You could use the max function, like this:

print max(var1, var2, var3, var4, var5)

It will tell you which number is the biggest (or max) of a set of numbers.
Bryan,

When I said it "eats whitespace", I meant it got rid of the spaces in the code.

Sorry about the confusion!

Carter
K,

You'd probably want to put the type-checking in a while loop. Then, you could ask the user over and over and over again until they finally decide to give your program a valid integer.
Here's some code that would do that.

input_valid = False
while not input_valid:
....q2 = (raw_input("What's your age?"))
....try:
........q2int = int(q2)
....except:
........print "You didn't enter an integer. Please try again."
....else:
........input_valid = True

Replace the dots with spaces, because this forum eats whitespace.

From,
Carter
You can put your code in a try-except block, like this:

try:
answer = int(raw_input("Type an integer: "))
except:
print "You didn't type an integer!!!"
else:
print "You typed in an integer."

This will check if Python can convert the input to an integer. If it can't, it will tell the user.

Carter
Matham,

I'm glad you're enjoying the book!

If you used the book's installer to install Python, you can find it in the Hello World folder in your Program Files or Applications folder. Just look for the folder called Answers.

Sorry about the confusion!

Carter
Hey Bennjamin,

Great project idea!

Just so you know, the code you posted on the forum isn't the same as the code you typed into IDLE. It's missing the indentation due to a bug with the forums. If you'd like other people to be able to use your code, you might want to try using a code sharing service such as Google Code or GitHub.

When you're designing an AI, you typically want to think about a strategy. What's a good strategy for playing Hearts? You can then turn that strategy into a set of rules for the computer.

Carter
Hey there!

It looks like you just made a simple typo.

_init_ (one underscore on each side)
should be:
__init__ (two underscores)

Let me know if that helps!

Carter
Hey Nicolas,

Glad you're enjoying writing your own programs! Are you reading the English or German version of the book? Just curious.

You can send your program to cp4khelp@yahoo.com

I'll check it out!

--Carter
Hi there,
Unfortunately, this forum takes off the whitespace at the start of lines. Therefore, we can't properly try to run your program.

However, if you e-mail us at cp4khelp@yahoo.ca and attach your program, we'll try and help you.

Carter
Sorry, I sent you the wrong address. It's cp4khelp@yahoo.com
Sorry,
Carter
Hi,

The error message you sent us indicates that Python is trying to find the graphics files, but it doesn't know where they are. Try placing the image files (they're in the skier folder of the Hello_World_Examples folder) in the same folder as your program.

Thanks,
Carter
This is happening because of Pygame's incompatibility with IDLE. (You can find out more about the incompatibility on page 176)

You can fix this by using SPE, where this problem doesn't occur.

Carter
We recommend using the installer on our web site. It installs Python 2.5 on your computer (but don't worry, any previously installed version will still work) as well as PyGame, PythonCard, and everything else you'll need.

Carter
Hi Cornelia!

The error message looks like PyGame wasn't installed properly. This probably isn't your fault.

Are you using the German translation of our book? It's the only one we know of with a CD, but we weren't exactly involved with its creation. Chances are, the installer on the CD didn't install PyGame correctly.

Also, what operating system are you using? Depending on whether you are using windows, mac, or linux, the installer might work differently. Let us know so we can test the installer on the correct operating system.

Sincerely,
Carter.
Any PythonCard function to open a dialog box takes at least one argument -- the window class that's opening it. You can see an example of this in the VirtualPet program. In the shell, you don't have that class to call it from. That's why the shell is giving you an error.

Also, could you send us the code you use to open the dialog from a program? You can e-mail us at cp4khelp@yahoo.com .

Carter
The square buttons are just a cosmetic issue with EasyGUI. That's because EasyGUI uses a different method to draw things on the screen. There's no way to make them round (that I know of) instead of square.

Also, the white square is just how BitmapCanvas is displayed in Resource Editor. It's a placeholder for whatever the program "paints" on the canvas. If you deleted it (even if it didn't disappear) then it would be gone from the resource file.

Thanks,
Carter
Hi there!

I'm guessing there is an indentation issue. This forum takes out indentation so I can't see what the problem is, so could you e-mail us the code at cp4khelp@yahoo.com?

Carter
I'm glad you're enjoying our book! Good job on figuring out the bug in your program.

Carter
It looks like (from your screenshot in your e-mail) you indented the last 5 lines too much. I've sent you a more detailed e-mail explaining the problem.

Carter
Could you please send us your code at cp4khelp@yahoo.com ? We'll look at it and see if we can figure out your problem.

Carter
It appears you have not defined the variable fahr. You just define it (or any other variable) like this:
fahr = 123


Hope this helps,
Carter
Your game is great! I started with the tutorial. It was simple, quick, and taught me what to do quickly. I started chugging along (built the robot generator, the fuel station, and some more stuff generators) and suddenly, I was attacked. Lucky for me, the gun building's auto-fire took care of the first bombs. Then, you highlighted the "mouse to shoot" control so I would notice it. After that, the game is still fun and addicting. Thanks for making it!

--Carter
Would you mind e-mailing us your code at cp4khelp@yahoo.com? Listing 8.8 works perfectly fine for us. There may be a slight typo in your code that stops it from working properly.

Carter
On a Mac, the new file option in IDLE is File->New Window. Also, make sure you are choosing IDLE in the MacPython 2.5 folder of your applications. It sounds like you are clicking on Python Launcher, which is the wrong program for what you're trying to do.

Hope this helps,
Carter
The reason sys.exit() is giving you an error is because that's how it works. Sys.exit() is designed to give you an error, which (in most cases) ends the program and closes the Pygame window.

Carter
Hi Aleksa,

I'm glad you're doing well with programming!

How you get Python onto the Internet depends on what you're trying to do. If you're just trying to let people download your programs, you can put them in a zip file and upload them to your website (along with your web pages).

However, you can also run Python programs that create your web pages. This is known as CGI, and not all web hosting supports it. You can find out more about it on http://www.penzilla.net/tutorials/python/cgi/

Carter
I got your e-mail. It turns out it was just a typo. Details in the e-mail I returned to you. Glad you're enjoying the book!

Carter
Please e-mail us the code at cp4khelp@yahoo.com

Sincerely,
Carter
I have a Mac with Snow Leopard, too. Although I don't usually get that error with IDLE, here are a couple things to look for:

If you have a firewall installed on your Mac, that's the most likely cause. You should either disable it or set it to allow IDLE.

Also, I occasionally have an issue where if IDLE crashes or you Force Quit it, it doesn't seem to register that it isn't connected anymore. This can cause subsequent launches of IDLE to not work. The only fix I've found for that is to reboot the computer.


Carter
You put the image files in the same folder as your program.

Carter