Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
word guessing game, hints
#1
hello
i struggle hard with this project.
the gamer needs to guess a word and i have figured everything out bur i want to give the gamer some help.
when he guesses and writes a whole word and it has some of the same letters as the word to guess the letters that are the same are printet in the spot as the gamer puts them in but in .lower(). if the leter is alo in the right spot as the word to figure out the letter will be .upper().
example
secret word: flower
gamers guess: gloppte
hint: _L O _ _ e
again gamer
guess: ffffff
hint: F f f f f f
and so on until he is right

hidden_word = 'flower' #random.choice(random_words) comes later
guess =''
guess_count = 0
hint = '_ ' * len(hidden_word)


print('Welcome to the word guessing game!')
print()

while guess != hidden_word:
   print(f'Your hint is: {hint}')
   guess = input('What is your guess? ').lower()

   # counts the guesses
   guess_count = guess_count + 1

   # this controls the lenghs of the guess
   if len(guess) > len(hidden_word):
     print('Sorry, the guess must have the same number of letters as the secret word.')
   elif len(guess) < len(hidden_word):
     print('Sorry, the guess must have the same number of letters as the secret word.')
     
#does not work 
   for char in hidden_word:
     if char.lower() in guess:
         print(char.upper, end='')
     else:
         print('_', end='')

#an other try to make it work but doesn t work either

   for letter in hidden_word:None
   
   if letter.lower() == guess.lower():
        print(letter.upper(), end='')
   else:
        print(letter.lower(), end='')
        
    
else:
   print('Congratulation! you guess it! ')
   print(f'It took you {guess_count} guesses. ')
   print()
does anyone of you have some ideas

thank you all so much
Reply
#2
https://python-forum.io/thread-43349.html
From your first post
Larz60+ likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  help with a script that adds docstrings and type hints to other scripts rickbunk 2 1,204 Feb-24-2025, 05:12 AM
Last Post: from1991
  word game, how to give hints STUdevil 5 1,518 Oct-07-2024, 06:20 PM
Last Post: STUdevil
  Guess the word game help jackthechampion 2 4,594 Sep-06-2023, 06:51 AM
Last Post: Pedroski55
Question Beginner Boolean question [Guessing game] TKB 4 4,251 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Unable to count the number of tries in guessing game. Frankduc 7 3,051 Mar-20-2022, 08:16 PM
Last Post: menator01
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 3,567 Aug-12-2021, 04:25 PM
Last Post: palladium
  Guessing game problem IcodeUser8 7 5,502 Jul-19-2020, 07:37 PM
Last Post: IcodeUser8
  Word Game paulmerton4pope 4 3,400 Jul-11-2020, 02:50 PM
Last Post: paulmerton4pope
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 3,804 Jun-18-2020, 04:59 PM
Last Post: QTPi
  SQLAlchemy with type hints gontajones 1 8,391 Jun-17-2020, 06:52 PM
Last Post: gontajones

Forum Jump:

User Panel Messages

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