A Professional’s Tutorial to Writing a Python Guessing Game

Junior capstone, having fun with Python, too!

Adam Ross Nelson
6 min readSep 17

For an overview of these tutorials, click here (or click the image).

Welcome to seventh, in a series of tutorials that teach beginner Python specifically for aspiring data scientists. For an overview of these tutorials, click here.


Data science often requires intricate algorithms, complex data manipulations, and the application of advanced statistical methods. However, the foundational skills revolve around and depend on basic programming principles.

One of the more classic introductory programming challenges you can work on in learning many programming languages is the number guessing game. This seemingly simple game offers an introduction to many fundamental concepts in Python programming.

A subsequent tutorial will introduce readers to a challenge that calls you to combine your knowledge of data types, flow control, and functions in a manner that is more closely related to data science: generating fictional data.

Two people with an all blue background. One person is whispering a secret in the other person’s ear.
Image Credit: Author’s illustration created in Canva.com.

This tutorial shows learners the process of creating a Python-based number guessing game. While the game itself might seem trivial for the experienced data professional, the underlying programming techniques such as exception handling, conditional statements, and user input are foundational for more complex applications in data science.

Import Statements

In Python, one often leans on external modules to tap into pre-defined functionalities. As an example of using a pre-defined function that ships with Python we will turn to the random function. Our guessing game requires the generation of random numbers, a task suitably performed by the random module.

import random

With this module imported, we can harness its functions, especially randint(), to produce random numbers within a specified range.

Helper Functions

The principle of “divide and conquer” applies very well in software development. Early learners will often…

Adam Ross Nelson

Ask about my free career course. I mentor new (💫) and aspiring data scientists enter (🚪) and level up (📈) in the field.