Sep-06-2023, 01:04 AM
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.
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.