How to Create a Guessing Game in Python
In this tutorial, we will program 'How to Create a Guessing Game in Python'. We will learn how to let the user guess a hidden word. The main goal here is to create a program that will display a hidden random word that the user will need to guess. I will provide a sample program to demonstrate the actual coding of this tutorial.
This topic is very easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show you covers the basics of programming for this guessing game. I will do my best to provide you with the easiest method for guessing the hidden word. So, let's start with the coding.
Getting Started:
First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.
Creating Main Function
This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.- import random
- print("\n============== Guess a word Game ==============\n")
- name = input("What is your name? ")
- print("Good Luck ! ", name)
- words = ['rainbow', 'computer', 'science', 'programming',
- 'python', 'mathematics', 'player', 'condition',
- 'reverse', 'water', 'board', 'geeks']
- word = random.choice(words)
- print("Guess the word")
- guesses = ''
- turns = 12
- while turns > 0:
- failed = 0
- for char in word:
- if char in guesses:
- print(char, end=" ")
- else:
- print("_")
- failed += 1
- if failed == 0:
- print("You Win")
- print("The word is: ", word)
- break
- print()
- guess = input("Enter a letter to guess: ")
- guesses += guess
- if guess not in word:
- turns -= 1
- print("Wrong")
- print("You have", + turns, 'more guesses')
- if turns == 0:
- print("You Loose")
This Python script implements a simple word guessing game. It randomly selects a word from a predefined list and prompts the player to guess the letters in the word. The player has a limited number of turns to guess the word. If the player correctly guesses all the letters, they win; otherwise, they lose after exhausting all their turns.
Output:

The How to Create a Guessing Game in Python source code that I provide can be download below. Please kindly click the download button.
There you have it we successfully created How to Create a Guessing Game in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
More Tutorials for Python Language