0% found this document useful (0 votes)
146 views8 pages

Computer Project - Hangman Game

The document describes a Hangman game project created by a student named Ishaaq Shaikh. It includes the game code and outputs showing a game being played where the secret word is guessed in 7 turns.

Uploaded by

Ishaaq Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views8 pages

Computer Project - Hangman Game

The document describes a Hangman game project created by a student named Ishaaq Shaikh. It includes the game code and outputs showing a game being played where the secret word is guessed in 7 turns.

Uploaded by

Ishaaq Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER SCIENCE

PROJECT (2020-21)

HANGMAN GAME

ISHAAQ SHAIKH
XI-A
Certificate

This is to certify that Ishaaq Shaikh of class XI – A of


International Indian School Dammam has completed
his project file under my supervision during the
academic year 2020-21. He has taken proper care and
shown at most sincerity in the completion of this
project.
I certify that this project is up to my expectations and
as per the guidelines issued by CBSE.

________________ ________________
(Internal Examiner) (External Examiner)
ACKNOWLEDGEMENT

Primarily I would thank God for being able to complete


this project with success.
Then I would like to thank my Computer Science
teacher, Ms. Maya Giby whose valuable guidance has
been the ones that helped me patch this project and
make it a full-proof success. Her suggestions and
instructions have served as a major contribution to the
completion of the project.
Then I would like to thank my parents and friends who
have helped me with their valuable suggestions and
guidance has been helpful in various phases of the
completion of the project.

SOURCE CODE :
import random, time
fruits = ['pear', 'mango', 'apple', 'banana', 'apricot', 'pineapple','cantaloupe',
'grapefruit','jackfruit','papaya']
superHeroes = ['hawkeye', 'robin', 'Galactus', 'thor', 'mystique', 'superman',
'deadpool', 'vision', 'sandman', 'aquaman']
userGuesslist = []
userGuesses = []
playGame = True
category = ""
continueGame = "Y"

name = input("Enter your name")


print("Hello", name.capitalize(), "let's start playing Hangman!")
time.sleep(1)
print("The objective of the game is to guess the secret word chosen by the
computer.")
time.sleep(1)
print("You can guess only one letter at a time. Don't forget to press 'enter key' after
each guess.")
time.sleep(2)
print("Let the fun begin!")
time.sleep(1)

while True:
#Choosing the Secret word
while True:
if category.upper() == 'S':
secretWord = random.choice(superHeroes)
break
elif category.upper() == 'F':
secretWord = random.choice(fruits)
break
else:
category = input("Please select a valid categary: F for Fruits / S for Super-
Heroes; X to exit")

if category.upper() == 'X':
print("Bye. See you next time!")
playGame = False
break

if playGame:
secretWordList = list(secretWord)
attempts = (len(secretWord) + 2)

#Utility function to print User Guess List


def printGuessedLetter():
print("Your Secret word is: " + ''.join(userGuesslist))

#Adding blank lines to userGuesslist to create the blank secret word


for n in secretWordList:
userGuesslist.append('_')
printGuessedLetter()

print("The number of allowed guesses for this word is:", attempts)

#starting the game


while True:

print("Guess a letter:")
letter = input()

if letter in userGuesses:
print("You already guessed this letter, try something else.")

else:
attempts -= 1
userGuesses.append(letter)
if letter in secretWordList:
print("Nice guess!")
if attempts > 0:
print("You have ", attempts, 'guess left!')
for i in range(len(secretWordList)):
if letter == secretWordList[i]:
letterIndex = i
userGuesslist[letterIndex] = letter.upper()
printGuessedLetter()

else:
print("Oops! Try again.")
if attempts > 0:
print("You have ", attempts, 'guess left!')
printGuessedLetter()

#Win/loss logic for the game


joinedList = ''.join(userGuesslist)
if joinedList.upper() == secretWord.upper():
print("Yay! you won.")
break
elif attempts == 0:
print("Too many Guesses!, Sorry better luck next time.")
print("The secret word was: "+ secretWord.upper())
break

#Play again logic for the game


continueGame = input("Do you want to play again? Y to continue, any other
key to quit")
if continueGame.upper() == 'Y':
category = input("Please select a valid categary: F for Fruits / S for Super-
Heroes")
userGuesslist = []
userGuesses = []
playGame = True
else:
print("Thank You for playing. See you next time!")
break
else:
break

OUTPUT :
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
= RESTART: C:\Users\acer\AppData\Local\Programs\Python\Python39\hangman
game.py
Enter your name ishaaq
Hello ishaaq let's start playing Hangman!
The objective of the game is to guess the secret word chosen by the computer.
You can guess only one letter at a time. Don't forget to press 'enter key' after each
guess.
Let the fun begin!
Please select a valid categary: F for Fruits / S for Super-Heroes; X to exitS
Your Secret word is: ______
The number of allowed guesses for this word is: 8
Guess a letter:
r
Oops! Try again.
You have 7 guess left!
Your Secret word is: ______
Guess a letter:
R
Oops! Try again.
You have 6 guess left!
Your Secret word is: ______
Guess a letter:
h
Oops! Try again.
You have 5 guess left!
Your Secret word is: ______
Guess a letter:
s
Nice guess!
You have 4 guess left!
Your Secret word is: __S___
Guess a letter:
v
Nice guess!
You have 3 guess left!
Your Secret word is: V_S___
Guess a letter:
i
Nice guess!
You have 2 guess left!
Your Secret word is: VISI__
Guess a letter:
o
Nice guess!
You have 1 guess left!
Your Secret word is: VISIO_
Guess a letter:
n
Nice guess!
Your Secret word is: VISION
Yay! you won.
Do you want to play again? Y to continue, any other key to quit

You might also like