PDA Assignments
  • Python For Data Analytics
    • 1.Python
      • 1.Python Documents
        • 1.Data Types
        • 2.Variables In Python
        • 3.Operators In Python
        • 4.User Input In Python
        • 5.TypeCasting In Python
        • 6.Strings In Python
        • 7.Conditional Statements In Python
        • 8.Branching using Conditional Statements and Loops in Python
        • 9.Lists In Python
        • 10.Sets In Python
        • 11.Tuples In Python
        • 12.Dictionary In Python
        • 13.Functions In Python
        • 14.File Handling In Python
        • 15.Numerical Computing with Python and Numpy
      • 2.Python Assignments
        • Data Type & Variables
        • Operators Assignment
        • User Input & Type Casting
        • Functions- Basic Assignments
        • String Assignments
          • String CheatSheet
        • Conditional Statements Assignments
        • Loops Assignments
        • List Assignments
          • List Cheatsheet
        • Set Assignments
          • Sets Cheatsheet
        • Dictionary Assignments
          • Dictionary Cheatsheet
        • Function Assignments
        • Functions used in Python
      • 3.Python Projects
        • Employee Management System
        • Hamming distance
        • Webscraping With Python
          • Introduction To Web Scraping
          • Importing Necessary Libraries
          • Basic Introduction To HTML
          • Introduction To BeautifulSoup
          • Flipkart Web Scraping
            • Scraping Step By Step
        • Retail Sales Analysis
        • Guess the Word Game
        • Data Collection Through APIs
        • To-Do List Manager
        • Atm-functionalities(nested if)
        • Distribution of Cards(List & Nested for)
        • Guess the Number Game
      • 4.Python + SQL Projects
        • Bookstore Management System
    • 2.Data Analytics
      • 1.Pandas
        • 1.Pandas Documents
          • 1.Introduction To Pandas
          • Reading and Loading Different Data
          • 2.Indexing and Slicing In Pandas
          • 3.Joining In Pandas
          • 4.Missing Values In Pandas
          • 5.Outliers In Pandas
          • 6.Aggregating Data
          • 7.DateTime In Pandas
          • 8.Validation In Pandas
          • 9.Fetching Data From SQL
          • 10. Automation In Pandas
          • 11.Matplotlib - Data Visualization
          • 12. Seaborn - Data Visualization
          • 13. Required Files
        • 3.Pandas Projects
          • Retail Sales Analysis
            • Retail Sales Step By Step
          • IMDB - Dataset Analysis - Basic
        • 2. Pandas Assignments
          • 1. Reading and Loading the Data
          • 2. Data frame Functions and Properties
          • 3. Series - Basic Operations
          • 4. Filtering in Pandas
          • 5. Advance Filtering
          • 6. Aggregate Functions & Groupby
          • 7. Pivot Tables
          • 8. Datetime
          • 9. String Functions
Powered by GitBook
On this page
  1. Python For Data Analytics
  2. 1.Python
  3. 3.Python Projects

Guess the Word Game

Python is a powerful multi-purpose programming language used by multiple giant companies. It has simple and easy-to-use syntax making it the perfect language for someone trying to learn computer programming for the first time.

In this Project, You have been provided to create a guess the word game which will choose a secret or magic word and ask the user to guess the word by providing the letters.

These letters provided must automatically be placed at the position where they are in the word so that user may understand and guess the magic word.

Your Program must provide 10 options to a user to guess and win the game.

Print the Appropriate Messages for clear understanding of the game.

Prerequisite

Python - Basic concepts

Random Module

This time the word is SNAKE

--------Guess the Word Game---------------
You Have 10 chances to win the game
You have to guess the secret word using letters
The letters will be placed automatically on the place if correct
Let's Start----->
_ _ _ _ _ 
Enter the character : o
_ _ _ _ _ 

Try Again!!
Enter the character : m
_ _ _ _ _ 

Try Again!!
Enter the character : a
_ _ a _ _ 

Try Again!!
Enter the character : n
_ n a _ _ 

Try Again!!
Enter the character : s
s n a _ _ 

Try Again!!
Enter the character : k
s n a k _ 

Try Again!!
Enter the character : e
s n a k e 

s n a k e 
You Won the Game
------------------------------------------

In this Guess may be wrong.

--------Guess the Word Game---------------
You Have 10 chances to win the game
You have to guess the secret word using letters
The letters will be placed automatically on the place if correct
Let's Start----->
_ _ _ _ _ 
Enter the character : n
_ _ _ _ _ 

Try Again!!
Enter the character : h
_ _ _ _ _ 

Try Again!!
Enter the character : a
_ _ _ a _ 

Try Again!!
Enter the character : e
_ _ e a _ 

Try Again!!
Enter the character : l
_ _ e a _ 

Try Again!!
Enter the character : s
_ _ e a _ 

Try Again!!
Enter the character : n
_ _ e a _ 

Try Again!!
Enter the character : m
_ _ e a _ 

Try Again!!
Enter the character : r
_ r e a _ 

Try Again!!
Enter the character : b
b r e a _ 

Try Again!!
You Lose the Game
----------------------------------------------
Solution
import random as rd

#List of words for guessing
words = ['SEVEN', 'SNAKE', 'APPLE', 'MANGO', 'TOMB', 'JERRY', 'HELLO'\
         , 'HAPPY', 'BREAK']

#function for printing _ _ _ _ _ and words on the right place
def print_place(lst):
    for i in lst:
        print(i, end=' ')
    print()


#Printing the game instruction
print('--------Guess the Word Game---------------')
print('You Have 10 chances to win the game')
print('You have to guess the secret word using letters')
print('The letters will be placed automatically on the place if correct')
print("Let's Start----->")

#selecting the word from the list of words
word = rd.choice(words)

#creation of a list for placing _ _ _ _ _
lst = ['_' for i in range(5)]

#Printing the first time
print_place(lst)
win = False
#running the loop for executing the game with 5 chances.
for i in range(10):
    char = input('Enter the character : ')
    for i in range(5):
        if word.lower()[i] == char:
            lst[i] = char

    print_place(lst)
    print()
    if "".join(lst) == word.lower():
        print_place(lst)
        win = True
        print('You Won the Game')
        print('------------------------------------------')
        break
    else:
        print('Try Again!!')            

if not win:
    print('You Lose the Game')
    print('----------------------------------------------')
PreviousRetail Sales AnalysisNextData Collection Through APIs

Last updated 2 years ago