In: Computer Science
In python Using the example code from the HangMan program in our textbook, create a Word Guessing Game of your choice. Design a guessing game of your own creation. Choose a theme and build your words around that theme. Keep it simple.
Note: I would highly recommend closely reviewing the HangMan code and program from Chapter 10 before starting work on this project. You can run the program via my REPL (Links to an external site.).
Using python Similar to our Number Guessing game, be sure to allow the player the option to keep playing and keep score. You can design the game however you see fit but it must meet these requirements:
General Requirements
Word lists
Output in python test and paste code
Guesses in python code show
Think the program through
Break this down into smaller sized concepts first. Walk through the program functions step by step. Here is some of my thought processes to get you started. Thank you for helping me
import wordlist
# Get a random word from the word list
def get_word():
word = wordlist.get_random_word()
return word.upper()
# Add spaces between letters
def add_spaces(word):
word_with_spaces = " ".join(word)
return word_with_spaces
# Draw the display
def draw_screen(num_wrong, num_guesses, guessed_letters,
displayed_word):
print("-" * 79)
print("Word:", add_spaces(displayed_word),
" Guesses:", num_guesses,
" Wrong:", num_wrong,
" Tried:", add_spaces(guessed_letters))
# Get next letter from user
def get_letter(guessed_letters):
while True:
guess = input("Enter a letter: ").strip().upper()
# Make sure the user enters a letter and only one letter
if guess == "" or len(guess) > 1:
print("Invalid entry. " +
"Please enter one and only one letter.")
continue
# Don't let the user try the same letter more than once
elif guess in guessed_letters:
print("You already tried that letter.")
continue
else:
return guess
# The input/process/draw technique is common in game
programming
def play_game():
word = get_word()
word_length = len(word)
remaining_letters = word_length
displayed_word = "_" * word_length
num_wrong = 0
num_guesses = 0
guessed_letters = ""
draw_screen(num_wrong, num_guesses, guessed_letters, displayed_word)
while num_wrong < 10 and remaining_letters > 0:
guess = get_letter(guessed_letters)
guessed_letters += guess
pos = word.find(guess, 0)
if pos != -1:
displayed_word = ""
remaining_letters = word_length
for char in word:
if char in guessed_letters:
displayed_word += char
remaining_letters -= 1
else:
displayed_word += "_"
else:
num_wrong += 1
num_guesses += 1
draw_screen(num_wrong, num_guesses, guessed_letters, displayed_word)
print("-" * 79)
if remaining_letters == 0:
print("Congratulations! You got it in",
num_guesses, "guesses.")
else:
print("Sorry, you lost.")
print("The word was:", word)
def main():
print("Play the H A N G M A N game")
while True:
play_game()
print()
again = input("Do you want to play again (y/n)?: ").lower()
if again != "y":
break
if __name__ == "__main__":
main()
here, In the word guessing python game, the user will guess the word that one has defined at the beginning like word 'tree', ' mango; etc,
users have the following benefits of this game:
Code of a word guessing game:
The output of the code is as:
i hope it helps..
If you have any doubts please comment and please don't dislike.
PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME