Python Forum

Full Version: Guess the word game help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have a guess the word game assignment need someone to help me fix it so the asteriks are synced with each word I did it before and just made the the words all the same length and got marked down, and then I need to make it to the word is being uncovered in the asterisks each time I guess a letter correctly I'm having issues figuring that out heres what I have so far

ie.
# Jack Crespin

#3/8/2020

#guess the word

import random 
 
  
name = input("What is your name? ") 
 
  
print("Good Luck ! ", name)

print ("Guess the word")
print("******")
  
words = ['accept', 'acting', 'advice', 'beauty',  
         'python', 'before', 'player', 'beyond',  
         'artist', 'branch', 'boards', 'branch']  
  

word = random.choice(words) 
  
  
print("Guess the characters") 
  
guesses = '' 
  

turns = 9000
  
  
while turns > 0: 
      
   
    failed = 0
      
    
    for char in word:  
          
       
        if char in guesses:  
            print(char) 
              
        else:  
            print("_") 
              
          
            failed += 1
              
  
    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 Loose")

input ("press enter to continue")
How would you do this with pencil and paper? Pretend you are playing this game with a friend. First you pick a secret word, "before" for example, and write the initial guess word replacing each letter in the secret word with "*":

Guess = ******

Your friend guesses "e" so you update the guess word to display:

Guess = *e***e

Your friend guesses "r" and you update the guess word to display:

Guess = *e***re

How did you do that? I did that by looking at the secret word, finding where my friend's letter guess matches letters in the secret word, and replacing "*" at those positions with the guessed letter. The game is won when there are no "*" in the guess word. The game is lost when max number of guesses is exceeded.

To translate to code lets first look for objects in the solution description (look for nouns). My solution uses the following objects:

secret word
letter guess
guess word
"*"

Next I look for actions:
pick
guess
finding
replace

The actions are things my program is going to do, and the objects are things my program is going to use.

The winning and losing criteria need some fleshing out to get nice objects and actions, but you've already got that part figured out I think.

Does that help?
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.
I think you need to work with lists, strings are difficult! Using ''.join(alist) you can turn the list back into a word.

See if you can complete this:

import random 
  
words = ['accept', 'acting', 'advice', 'beauty',  
         'python', 'before', 'player', 'beyond',  
         'artist', 'branch', 'boards', 'branch']    
 
word = random.choice(words)
wordlist = [ch for ch in word]
print('The word is', len(word), 'letters long ... ')
hintlist = ['*' for ch in word]
aguess = input('Enter a character or a whole word. ')
if aguess == word:
    print('You guessed it! The word was', word)
else:
    for i in range(len(wordlist)):
What should be in the loop?