Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:52:00+00:00 2026-06-14T19:52:00+00:00

I have one question regarding this hangman program of mine.When I guess the a

  • 0

I have one question regarding this hangman program of mine.When I guess the a letter(‘o’) right of a word(“good”) which has duplicates,it’s being unveiled only for the first index as list.index(value) returns only one index even if there are duplicates of that value.What do I need to change or add if I want to unveil all the duplicate letters at the same time.

Here’s what I Expect the program to do:

Guess the letter: l >>> _oo_

Thanks.

the_word="good"
#print the_word
wLen=len(the_word)
u='_'*wLen
counter=0
while counter!=12 and wLen!=0:
    counter=counter+1
    print u
    g=raw_input("Guess the letter: ")
    p=list(the_word)
    x1=the_word.find(g)
    if x1 >=0:
        u1=list(u)
        u1[x1]=g
        u=''.join(u1)
        wLen=wLen-1

if wLen==0:    
    print "Congratulation!!!you have guessed the word"
    print "The word was",the_word

else:
    print "sorry u loose"  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:52:01+00:00Added an answer on June 14, 2026 at 7:52 pm

    In case this is for an assignment, I’ll focus on a simpler solution that will hopefully make sense. You know your target word, and from that you can use a function called enumerate to find the index positions of all of the letters:

    In [31]: word = 'good'
    
    In [32]: for index, letter in enumerate(word):
       ....:     print index, letter
       ....:
    0 g
    1 o
    2 o
    3 d
    

    So knowing this, let’s say a user inputs o. Our current ‘guessing’ string looks like ____, and we know that we need to replace index positions 1 and 2 with o. Since the guess string and the target word have the same length (since they are supposed to be the same word), one simple solution would be to iterate over the actual word with enumerate, and if the letter is o (or whatever they guessed), replace the same index position in the guessing word with that letter. For example:

    In [33]: word = 'good'
    
    In [34]: guess_list = list('_' * len(word))
    
    In [35]: g = raw_input('Guess a letter: ')
    Guess a letter: o
    
    In [36]: for index, letter in enumerate(word):
       ....:     if letter == g:
       ....:         guess_list[index] = letter
       ....:
    
    In [37]: print ''.join(guess_list)
    _oo_
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding the some data which is being transfered from one
I have one question regarding trigger. The scenario is like this Create Procedure begin
I have question regarding the service and activity. I have one service which calls
I use Visual Studio 2008 and have a question regarding this warning. In one
I have a question regarding the following code snippet I came across in one
I am learning JPA and have one question: In which situations we need more
I have one question regarding design of my application. Here's the pseudo code: char*
I have general question regarding the use of pointers vs. references in this particular
I have this question regarding memory allocation and deallocation in c++. Here is the
This is most certainly a language agnostic question and one that has bothered me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.