Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guess the word game help
#3
Based on the code you've shared, it seems like you're working on a word guessing game. However, you want to ensure that the asterisks "******" are synchronized with the guessed word, and each time you correctly guess a letter, the word is revealed within the asterisks.

To achieve this, you can use a tool like "word finder" to find words of the corresponding length to the number of asterisks and then randomly select a word from that list. Here's an example of how you can incorporate the use of the Word Finder tool into your code:

python
Copy code
import random
from wordfinder import WordFinder # This is a hypothetical Word Finder tool

# Initialize the Word Finder tool with the list of words to search from
word_finder = WordFinder(['accept', 'acting', 'advice', 'beauty',
'python', 'before', 'player', 'beyond',
'artist', 'branch', 'boards', 'branch'])

name = input("What is your name? ")

print("Good Luck! ", name)

print("Guess the word")
word = word_finder.get_random_word() # Get a random word from the Word Finder tool
hidden_word = "*" * len(word)

print(hidden_word)

guesses = ''
turns = 9000

while turns > 0:
failed = 0

for char in word:
if char in guesses:
print(char, end=" ") # Print the correctly guessed characters
else:
print("_", end=" ") # Print an underscore for unknown characters
failed += 1

print() # Print a newline for formatting

if failed == 0:
print("You Win")
print("The word is: ", word)
break

guess = input("Guess a character: ")

guesses += guess

if guess not in word:
turns -= 1
print("Wrong")
print("You have", + turns, 'more guesses')

if turns == 0:
print("You Lose")

input("Press enter to continue")
In this modified code, I've replaced the direct selection of a word from the list with the use of the Word Finder tool to get a random word. Additionally, I've adjusted the printing of guessed characters to make it more user-friendly.
Reply


Messages In This Thread
Guess the word game help - by jackthechampion - Mar-30-2020, 12:29 AM
RE: Guess the word game help - by deanhystad - Mar-30-2020, 01:01 AM
RE: Guess the word game help - by annajenny - Sep-06-2023, 01:04 AM
RE: Guess the word game help - by Pedroski55 - Sep-06-2023, 06:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Ask again if wrong guess with While. EduPy 4 2,292 Oct-21-2021, 07:46 PM
Last Post: menator01
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,551 Aug-12-2021, 04:25 PM
Last Post: palladium
  I guess it's about print tsavoSG 2 2,147 Feb-08-2021, 08:34 PM
Last Post: steve_shambles
  Word Game paulmerton4pope 4 2,474 Jul-11-2020, 02:50 PM
Last Post: paulmerton4pope
  Python Speech recognition, word by word AceScottie 6 16,080 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 4,929 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  can't figure out problem with number guess Galoxys 4 3,389 Oct-29-2018, 01:45 PM
Last Post: snippsat
  Guess a number Ameen 5 13,189 Apr-03-2018, 01:20 PM
Last Post: snippsat
  difference between word: and word[:] in for loop zowhair 2 3,705 Mar-03-2018, 07:24 AM
Last Post: zowhair
  Guess Random Number Why i m not able to enter input Nithya Thiyagarajan 6 8,268 Jan-07-2018, 04:26 AM
Last Post: squenson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020