A Professional’s Tutorial to Writing a Python Guessing Game
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.
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.
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
With this module imported, we can harness its functions, especially
randint(), to produce random numbers within a specified range.
The principle of “divide and conquer” applies very well in software development. Early learners will often…