Python is a powerful multi-purpose programming language used by multiple giant companies. It has simple and easy to use syntax making it perfect language for someone trying to learn computer programming for first time. It is a high-level programming language, and its core design philosophy is all about code readability and a syntax which allows programmers to express concepts in a few lines of code.
In this article, we will use random module to make a word guessing game. This game is for beginners learning to code in python and to give them a little brief about using strings, loops and conditional(If, else) statements.
random module :
Sometimes we want the computer to pick a random number in a given range, pick a random element from a list, pick a random card from a deck, flip a coin, etc. The random module provides access to functions that support these types of operations. One such operation is random.choice() method (returns a random item from a list, tuple, or string.) that we are going to use in order to select one random word from a list of words that we’ve created.
In this game, there is a list of words present, out of which our interpreter will choose 1 random word. The user first has to input their names and then, will be asked to guess any alphabet. If the random word contains that alphabet, it will be shown as the output(with correct placement) else the program will ask you to guess another alphabet. User will be given 12 turns(can be changed accordingly) to guess the complete word.
Below is the Python implementation:
What is your name? Gautam Good Luck! Gautam Guess the characters _ _ _ _ _ guess a character:g g _ _ _ _ guess a character:e g e e _ _ guess a character:k g e e k _ guess a character:s g e e k s You Win The word is: geeks
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Number guessing game in Python 3
- Number Guessing Game in Python using Binary Search
- PyQt5 - Number Guessing Game
- Python program to read file word by word
- Python | Program to implement Jumbled word game
- PyQt5 – Jumble Word Game
- Python | Program that matches a word containing 'g' followed by one or more e's using regex
- Python program to capitalize the first and last character of each word in a string
- Python program to find the character position of Kth word from a list of strings
- Python Program to Return the Length of the Longest Word from the List of Words
- Python program to remove Nth occurrence of the given word
- Python program to capitalize the first letter of every word in the file
- Python | Program to implement simple FLAMES game
- Python program to implement Rock Paper Scissor game
- Program to replace a word with asterisks in a sentence
- Program to find the Encrypted word
- Python | Word Similarity using spaCy
- Python | Reverse each word in a sentence
- Find frequency of each word in a string in Python
- Generating Word Cloud in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : anshitaagarwal