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 8866199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:43:43+00:00 2026-06-14T16:43:43+00:00

I have a hangman type game which displays the secret string as dashes. So

  • 0

I have a hangman type game which displays the secret string as dashes.

So in this case, the secret string is ‘+*794242’, which will first be displayed as ‘——–‘. Now, the takeguess function takes the guessed number and replaces the correct corresponding dash with it. This works for the initial guess, but any gueses afterwards makes the partial variable longer (partial displays the guesses and dashes, ex: ‘–7-4-4-‘).

I began by splitting it to see if it’s the initial guess where partial is blank. I’m not sure why it keeps making the partial string longer after each guess. You’ll see what I mean! Also, if there’s any other better way to do this, I’d like to know after I solve this problem! Thank you!

secret = '+*794242'
partial = ''
def takeguess(a):
    incomp = ('-' * len(secret))    #Dashes
    if partial == '':        # If just starting (first guess), partial is blank
        for i in range(0,len(secret)):
            if guess == secret[i]:
                global partial
                partial = partial + guess
            else:
                global partial
                partial = partial + incomp[i]
        return partial
    else:       # After initial guess, partial won't be blank, this is where I need help
        for i in range(0,len(secret)):
            if guess == secret[i]:
                global partial
                partial = partial + guess
            else:
                global partial
                partial = partial + incomp[i]
        return partial

while True: #Example while true
    guess = raw_input('Enter guess: ')
    takeguess(guess)
    print partial
  • 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-14T16:43:45+00:00Added an answer on June 14, 2026 at 4:43 pm

    If you use a set, you could simplify even more.

     message = '+*794242'
     currentLetters = set()
     currentMessage = ''
    
     def takeguess(letterGuess):
       if letterGuess in message:
         currentLetters.add(letterGuess)
    
     while message != currentMessage:
       takeguess(raw_input('Enter guess: '))
       currentMessage = ''.join([l if l in currentLetters else '-' for l in message])
       print currentMessage
    

    Tips:

    • ‘partial’ was once a reserved keyword. It is no longer reserved, but it is probably good to not use it to avoid confusion.
    • Never write the same code twice. That causes much confusion.
    • When dealing with items which can’t be duplicated (characters, in this case) use a set, not a string.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a very specific question regarding my Hangman program. You will probably want
I have made a hangman game in Python, and stupidly didn't save as before
I'm currently busy coding a hangman game in VB.NET. As a wordlist, I have
Have data that has this kind of structure. Will be in ascending order by
I'm porting a Hangman game to Android and have met a few problems. The
For a class project, we have to create a hangman game in Java (we're
I am writing a hangman game program in python and have run into a
I have made a basic hangman game on Netbeans, and the way it works

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.