Get from the tee to the hole in as few shots as possible.
Learn to code a Python Golf game. This coding project includes all of the code, images and audio files required to make the game.
Starter Code Files
Download and unzip this starter Python code file to your Golf project folder
Images and Audio
Download and unzip these image and audio files to your Golf project folder
Book of Code
Copy the Golf Python program from the Book of Code into your IDE
1. String Variable: slider_direction
A string is a sequence of characters. In this tutorial you will learn how to use a string variable.
Watch first: Alien Invasion Strings
2. List: hole_strokes
A list in Python is a structure for storing multiple data items. In this video we explain how to use a list to store the number of strokes taken at each hole.
Watch first: Forest Bomber Lists
Buy the book
Forest Bomber is one of the four games covered in the book Game Programming with Code Angel, available on Amazon now.
3. For Loops
In Python a for loop is used to repeat something a certain number of times. In the game of golf we use a for loop to display each hole on the scoreboard.
Watch first: Snapper Integer Variables 2
Difficulty level: 3
4. If: Draw the Flag
In this video you will learn how the Python if statement is used in the golf game to decide which hole flag to draw.
Watch first: Snapper If and Elif
Difficulty level: 2
Learn how to use the Python or operator to build more complex if statements.
Watch First: Alien Invasion And
6. Random Flag
In this video we explain how to use Python’s random.randint() function to determine where to draw the flag on each golf hole.
Watch first: Snapper Random Randint
7. Move Ball Logic
In this tutorial we will take a closer look at the game code logic used to move the golf ball across the screen.
Watch first: Golf Random Flag
8. Nested If
You have learned from previous tutorial videos that if statements can be used to make decisions in Python. In this video we demonstrate how if statements can be nested.
Watch First: Random Flag Placement
9. Variable Names
When coding games in Python, it is important to use meaningful and readable variable names. In this video we explain how camel case and macro case can be used to make variables and constants more readable.
Watch first: Snapper If Elif
Ring Video Doorbell 2 | 1080p HD Video, Two-Way Talk, Motion Detection, Wi-Fi Connected, available on Amazon