We may earn an affiliate commission when you visit our partners.
Trevor Sawler

Python is one of the world's most popular programming languages, and with good reason: it is extremely flexible, easy to learn, and runs on a wide variety of devices and platforms. In fact, Python recently moved to first place in the TIOBE programming community index, which is a remarkable achievement.

Read more

Python is one of the world's most popular programming languages, and with good reason: it is extremely flexible, easy to learn, and runs on a wide variety of devices and platforms. In fact, Python recently moved to first place in the TIOBE programming community index, which is a remarkable achievement.

This course is an introduction to Python, version 3.10. Unlike many introductory courses, we will not spend hours surveying the basics of the language; personally, I see no point in doing that, since there are already many, many free resources online that do precisely that. Instead, we'll learn the language in the way that I have long preferred: we'll actually build something.

The bulk of this course will be focused on building a simple text adventure game, where the player explores a labyrinth, encounters monsters, engages in combat, finds items, and that sort of thing. It's a bit of a throwback to the early days of computer games, but the important thing here is not the quality of the game that we'll build, but rather that we'll cover all of the things you need to get started programming in Python, including:

  • Python's primitive data types: integer, float, string, and boolean

  • Python's aggregate data types: tuple, set, dictionary and list

  • How to make decisions in Python: if/elif/else

  • How to loop in Python: for and while loops

  • How to write functions

  • How to import from the standard library, and third party packages

  • How to structure a Python program

  • How to perform mathematical operations in Python

  • How to manipulate strings in Python

  • How to work with classes in Python

And, as the saying goes, much more. Periodically, I'll include "aside" lectures, which focus on a particular aspect of Python in more detail, with simple code examples that are not part of the main project.

This course requires no previous programming experience.

Enroll now

What's inside

Learning objectives

  • Learn the basics of python, one of the most popular programming languages in use today
  • Learn the syntax of the python language by writing a text-based adventure game
  • Learn about the difference between object-oriented and procedural programming
  • Learn to think like a computer scientist: making decisions, looping logic, and performing calculations
  • Learn best practices when writing python code
  • Learn how to build a terminal-based python program
  • Learn how to create a virtual environment to isolate your program and make it easy to install

Syllabus

Another aside: functions
Implementing a while loop to keep the program running

Let's figure out how to capture user input.

Installing Python (a recent version) and an IDE.
Read more

Just an introduction, and an overview of what we are going to be covering in this course.

A brief note about my background.

Macs come with Python installed by default, and you can use that, but you can install the latest version if you wish.

Windows does not include a python distribution by default. Let's install one.

Installing the PyCharm CE
Python resources and documentation
How to ask for help

For the most part, programming languages either compile source code to a binary, or run the source code through an interpreter in order to execute commands. But some languages, like Python, fall in between these two categories. Here is a brief explanation.

Let's go over the basics of Python, programming in general, and get started with our adventure game.

Let's write the customary "Hello, world!" program in Python. It's only a single line of code, but it's a start.

Let's get started with the basic structure of a Python program.

Strings, integers, booleans and floats.

You can put variables almost anywhere you want in a Python file, but where you put them matters. Let's talk about scope.

Getting started with our adventure game

Let's get started on making decisions based on what a user types in, and give the player the option of showing a help screen and quitting the game (or playing again).

Let's have a look at Python's comparison operators and logical operators. We'll be using them a lot, so a brief overview seems appropriate.

Let's make sure that we sanitize whatever the user types, and let's finish up printing our help information.

Let's spice things up a bit by adding colour to our application, and figuring out how to clear the screen before the game starts.

Making the Game functional with Classes

Classes are incredibly useful, and we'll be using them throughout the remainder of this course. Let's explore them a bit.

We need something to keep track of the player as he or she progresses through the game, so let's create a Player class to take care of this for us.

We need somewhere to store information about every room in the game, so let's create a Room class to take care of this.

Let's define a Game class that will hold the current player, the room that the player is currently in, and all other important game related information.

Let's get started using our Player, Room, and Game classes in our adventure game.

Tuples are like lists: they are one of Python's four data structures which allow us to store more than one thing in a variable. Let's use tuples to help provide more realistic descriptions for our game.

Let's get started with allowing players to navigate around the dungeon.

Like lists and tuples, dictionaries are data structures in Python that let us store more than one thing in a variable. Unlike lists and tuples, though, dictionaries allow us to store things using key-value pairs. Let's see how they work.

We have a lot of items in our armory.py file, so let's put some in our rooms, to give the player something to find. Let's also decide if a room should have a monster or not.

Let's allow our player to pick things up, equip and unequip them, and drop unwanted items.

An overview of the Python list data type, and adding an attribute to the Player class to keep track of inventory.

Let's get started with the logic of allowing players to pick items up.

Let's finish up the code for picking an item up, and removing it from the room once we've done so.

Let's write a simple function that allows the player to print out the contents of the current inventory.

An aside: more about looping

Right now, room descriptions are displayed every time we enter a command. That's no good, so let's clean our code up a bit.

Let's implement the functionality that allows the player to drop an item, and while we're at it, let's learn about the "try/except" functionality in Python, which is similar to "try/catch" in other languages.

We can now let players find items, drop items, and show the current inventory, so let's allow them to equip, or use, weapons, armor, and shields.

Let's show the player what items from their inventory that they have equipped, and let's consider how to solve one problem that we have in the game. Plus, I give you a bit of a challenge.

Here's how I solved the challenge.

Players can now find items, pick up items, use items, and drop items, and view the inventory. The last step is to let them "unequip," or stop using items. Let's take care of that.

Let's implement the "status" command, so players can see how well they are doing in the game.

An aside: different ways of printing strings with variables
Let's implement a simple combat system, where the player and the monster fight it out.

A brief overview of how combat is going to work in our adventure game.

Let's get started with combat by letting the player run away when they encounter a monster.

Let's begin with the combat logic by determining who gets to attack first.

Let's get the initial code in place for the player's turn during combat.

Now it's the monster's turn, so let's implement the logic for this part of the fight.

If the player is doing badly in the fight, they should have the chance to run away. Let's write that logic.

Once a fight is over, the player should get feedback, one way or the other, and if the monster lost, we need to make sure that the monster is taken out of the game. Let's take care of that.

Combat should be harder (or easier) depending on what armour, weapons, or shield the player has, and depending how strong the monster is. Let's adjust our math accordingly.

Let's allow the player to rest in order to regain health.

Let's implement a simple mapping system, and allow the player to check their location while playing the game.

Let's have a look at what the final map will look like.

We need to make some changes to the Game class to tell it about the map. Let's do that.

Prepopulating all rooms in the map

Player's should not be allowed to move "outside" of the map. In order to prevent that, we need to keep track of where the player is, and check that against the current map's dimensions. Let's do that.

Syntax errors are easy to spot, since your editor typically points them out to you. Logic errors are tougher. Here is a challenge that focuses on logic errors.

Let's try out our code and modify it so that it keeps track of the player's current position on the map.

Let's take advantage of the attribute "visited" that we added to the Player class in order to keep track of where the player has been on the map.

Let's get started implementing the "map" command to show a map to the player.

Let's make the map show us useful information.

Let's finish up our map command by adding some lines at the top and bottom, and adding a legend.

Improving the game interface

Let's give our player an easy way to see how things are going by using the blessings package to add a status bar at the top of the screen.

Challenge: revise welcome text to explain why players have no weapons or armor

There are only a few things left to take care of in the game; let's write the last bit of code.

Save this course

Save Working with Python - Introductory Level to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Working with Python - Introductory Level with these activities:
Review Basic Python Syntax
Reinforce your understanding of fundamental Python syntax, including variable assignment, data types, and operators, to ensure a smooth start to the course.
Browse courses on Python Syntax
Show steps
  • Read through a Python syntax cheat sheet.
  • Write short code snippets to practice each concept.
  • Complete online quizzes to test your knowledge.
Review "Python Crash Course"
Solidify your understanding of Python fundamentals by working through the exercises and projects in "Python Crash Course."
Show steps
  • Read the first few chapters covering basic Python concepts.
  • Complete the exercises at the end of each chapter.
  • Attempt one of the larger projects to apply your knowledge.
Practice Python Data Structures
Sharpen your skills in using Python's built-in data structures (lists, tuples, dictionaries, sets) through targeted practice exercises.
Show steps
  • Solve coding problems involving list manipulation.
  • Implement dictionary lookups and updates.
  • Work through exercises involving set operations.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Review "Automate the Boring Stuff with Python"
Explore practical applications of Python beyond game development to broaden your understanding of the language's capabilities.
Show steps
  • Read chapters related to file manipulation and web scraping.
  • Try implementing some of the automation scripts described in the book.
  • Adapt the scripts to solve your own real-world problems.
Document Your Text Adventure Game Journey
Reinforce your learning by documenting your progress, challenges, and solutions while building the text adventure game.
Show steps
  • Create a blog or journal to record your experiences.
  • Write about the design decisions you made and why.
  • Share code snippets and explain their functionality.
  • Reflect on what you learned from each module.
Expand the Text Adventure Game
Deepen your understanding of Python by adding new features and complexity to the text adventure game.
Show steps
  • Implement a more sophisticated combat system.
  • Add more items, monsters, and rooms to the game.
  • Introduce puzzles and challenges for the player to solve.
  • Incorporate a scoring system and a game-ending condition.
Contribute to a Python Game Library
Apply your Python skills by contributing to an open-source game library or framework.
Show steps
  • Find a suitable open-source project on GitHub.
  • Read the project's documentation and contribution guidelines.
  • Identify a bug to fix or a feature to implement.
  • Submit a pull request with your changes.

Career center

Learners who complete Working with Python - Introductory Level will develop knowledge and skills that may be useful to these careers:

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Working with Python - Introductory Level.
Python Crash Course great book for beginners to get up to speed with Python. It covers the basics of Python programming in a clear and concise manner. It includes hands-on projects that allow you to apply what you've learned. is particularly useful for those with little to no prior programming experience.
Provides practical examples of how Python can be used to automate everyday tasks. While not directly related to game development, it reinforces core Python concepts and demonstrates the language's versatility. It's a good resource for expanding your Python knowledge beyond the scope of the course. This book is commonly used as a reference for automating tasks.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser