Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

thepenguin

  • 3 years ago

Can anyone give me a suggestion on how to get the letters into the word in the hangman game in ps2? I am trying to get it to input the letters in the appropriate place in a chain of dashes. For example, for the word 'happy', it would print this '-----'. What I can't get it to do is, like if i guess 'a', input 'a' into the place of the proper dash, i.e. '-a---'. Any suggestions?

  • This Question is Closed
  1. RoamingBlue
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    http://dpaste.com/hold/786671/ answerWord = 'happy' dashedWord = '_____' # Check for the following letterst (just to test) for letterGuessed in ('a', 'p', 'y', 'h'): # loop through the entire answer to see if that character is present for index in range(0,len(answerWord)): # if we find the letter if answerWord[index] == letterGuessed: # this here's the important bit ################################################### # you can't actually change strings in Python # so you have to create a new string and build it from the old one # this builds the new string from: # the substring from 0 up to but not including the letter we need to insert # plus the correct letter we need to add in # plus the substring from the NEXT letter to the end of the string dashedWord = dashedWord[0:index] + letterGuessed + dashedWord[index+1:len(dashedWord)] print dashedWord

  2. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy