Data and AI Training

Home | Prices | Contact Us | Courses: Power BI - Excel - Python - SQL - Generative AI - Visualising Data - Analysing Data

Python Foundation (Snake Game Version) Course

python snake game

Who should attend

Anybody who want to learn Python. This course focusses on the features of the language itself. It hopes to do this in a way that is more fun and interesting than a more traditional approach, and so possibly more relevant to people who have not coded before

Course Length

2 days

Learning Objectives

This will introduce you to Python and give you the opportunity to practice many of the features of the language: variables and constants, writing functions, creating and using classes, data structures, importing packages, looping and branching.

Pre-requisites

None. This is a beginner level course.

Course Content

We will learn Python by writing the classic game of snake. This may seem a frivolous exercise compared to a more serious use case of, for example, data analysis. However, writing a game like this one forces us almost immediately to use many of the features of the language. We start by creating variables and constants to set up our screen and snake. We implement our snake firstly as a Python data structure (a list of tuples) and use list methods such as append and pop to make our snake move. To keep our code organised and readable, we create a Snake class so that our snake can move, hiss and eat. We use looping, (with the for and while keywords) so that the snake responds to our key presses and conditional flow (with the if keyword) so that it eats and grows when it finds food. We learn how to install and import packages.

We also use AI tools occasionally to help us with the grunt work of getting the exact correct syntax we need. But the hard thinking how to design and implement the game is up to us.

One of the good things about this case study is that it is always apparent when things have gone wrong e.g. our snake refuses to move or grow, or disappears off the screen. Testing involves playing the game a lot!

Joining Instructions

Before the course, attendees need to install Python and VSCode on their PC/ Mac. This course does need a local installation of Python. A remote installation such as Google Colab or GitHub workspaces will not work.

Here are the instructions.

Download Python from https://www.python.org/downloads/ and install on your PC/Mac.

Download VSCode from https://code.visualstudio.com/download and install on your PC/Mac.

Launch VSCode then:

  1. install the Python extension,
  2. create a new project and folder
  3. create a new .venv virtual environment for this project
  4. create a terminal window and type “pip install pygame” (This is the package that contains some basic functionality that we need)

Copy this Python file into the project folder.

Run the Python file. In the terminal window, type “py snake_game.py”. This should open a new window similar to the snapshot below

Close the window. You are now ready to start the course.