Python is an evolving, high-level programming language, that is widely used by tech giants such as Facebook and Netflix in their daily operations. And Python—as a programing language—improves drastically with each new version, making it the most powerful as well as user-friendly programming language in the world.
Python is a great language to use to create games and interactive projects. So today, we'll explore a few easy Python games for beginners. Read along as we break things down with a step-by-step tutorial for making a simple Python game, too. To dive more in-depth with Python, explore the best Python classes for kids.
Free Python games
Let's get started with a few fun free Python games to try to build your skills.
1. First Interactive Program with Python on trinket.io
This is an excellent first project to create if you are a beginner who is interested in learning about Python. This project includes powerful methods like listen() and click() which can trigger events like the change of color of a Sprite and screen. It also includes familiar features like “go to” (goto()) method where x and y axis of a Sprite can be changed based on a given condition and/or function. If you are familiar with Scratch, this project will give you an idea of how Scratch and Thunkable blocks work behind the scenes.
2. React to Click and Key Events using Python on trinket.io
We are fans of trinket.io – the pioneer of today’s interactive modules and a popular platform that allow users to create simple but powerful interactive projects with Python. In this game, titled “Turtles in Space”, you can continue to learn about listen() method and get an idea of how a game can react to not only clicks, but key events as well (keyboard keys). Much like Scratch, this exercise shows you how events are triggered based a key that’s pressed by a user. This is another amazing feature derived from the listen() method in Python.
3. The 21 Game with Python on trinket.io
This is a human versus computer game where the computer picks and outputs a
random number using Python’s random module. Then the game prompts the user to input numbers 1, 2, or 3 which adds on to the random number that was previously picked. The goal for the user is to avoid inputting a number that will, when added, exceed 21. In the meantime, the program behind The 21 Game is set to check for the winner using logic like if/then/else conditions and while loops.
Making simple games in Python
Simplicity wins! So, no matter how confident of a programmer you may be, always start off by making a simple game in Python. To help you get started, we have put together a step-by-step tutorial for a simple Python game we call Write a Message.
STEP 1: Sign up or log into Thrinket.io
If you haven’t already, create an account on trinket.io by going to trinket.io/signup then hover over your name in the upper right corner and select “New Trinket” and then “Python”.
STEP 2: Overview and Helper.py File
We want to add a background and a character “Snoops the dog” who is going to brighten up our day by drawing a simple smiley face and writing a message of the user’s choice at the bottom of the page.
Helper.py file will be used for importing the turtle module which allows for graphic-like designs. Inside of Helper.py file we’ll define the background and the image which we will pull into the main file where we will write our code. To add a text file, click on the plus sign on the top right and enter the following text:
STEP 3: Set the Background and the Character
Click on the main.py tab and start with importing the helper file that we created previously. Both the background as well as the character are an image type of a document, we just need to type out their exact file names inside of the parenthesis. Don’t forget the double quotes around each. To see what it looks like so far, click on the right pointing triangle icon right above the main.py and helper.py tabs.
STEP 4: Instruction Line and User Text Input
Let’s print a message to the users before Snoops the dog gets to work. Use print() and enter the text of your choice to prompt the user to enter what they’d like to see at the bottom of the screen. Then create a variable where the user’s input will be stored. We named our variable “user_choice”:
STEP 5: Snoops the Dog Drawing
Much like the blocks in motion category on Scratch coding, Python has something similar. The syntax is different, but functions are the same. For example, if you noticed Snoops the dog is currently sideways, that can be corrected by using left() or right() method.
We can also draw using the pendown() method and stop writing with penup() which may seem familiar if you’ve used the Pen extension in Scratch. The forward() and backward() methods move our character back and forth and circle() method can be used for circular motions. For drawing, the thickness of the line can be controlled with the pensize() method:
STEP 6: User’s Message
All there is left to program is the part where Snoops the dog will write the message that was typed up. Python uses write() method to output any text, or in our case, the text (message) that was stored inside of our user_choice variable:
Try Python games for beginners
Python is a very popular programming language, and not only because it is as dynamic as it is powerful language, but also because its English-like syntax which makes coding easy and fun. It's a great option for learning coding for teens! If you enjoy Python as much as we do, learn more from our experienced Python teachers by signing up for our online Python classes. And check out fun Python exercises.
Written by Sandra Dizdarevic, a Create & Learn instructor with 6 years of experience teaching STEM to children in the 3rd through 11th grade. She has an Undergraduate as well as a Masters Degree in Management Information Systems from UNO.