📅 2023-Jan-15 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ book, python ⬩ 📚 Archive
Coding Games in Python is a 2018 book that introduces programming to kids using Python to create simple games. I found that directly following the instructions from the book would not work with Python 3.10 on Windows.
Below are some changes you need to do to get the code from the book working:
The book asks the reader to type the code in the IDLE editor and run it. The IDLE that ships with Python 3.10 seems to show the interpreter instead of the editor by default. So, a child that directly follows the instructions in the book will be stumped why their code is not running.
This can be switched by choosing Options -> Configure IDLE -> Windows and for At Startup choose Open Edit Window. Restart IDLE, it should show an editor window. In case there is some text (like the opening text from Python interpreter) in the editor, delete it all.
Remember that to run the typed code, choose Run -> Run Module. It opens an interpreter window where the code is executed. Close that window or any other secondary windows it spawns once you have viewed the results.
PyGame Zero seems to have been designed to work without having any import. This is why the code in the book surprisingly does not have any import statements.
However, that might have been true for an older version of PyGame Zero. But now it seems like you need to have
import pgzrun in the file.
Type the above import line in all the files or chapters that use this module.