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

This is run either as a 2 day courses, or as a series of six 2-hour sessions.

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!