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?
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
Join our real-time social learning platform and learn together with your friends!