guess the word game in python - how to mask a word (eg. ------)
<p>I'm writing a guess the word game in python. It's for my school project. I'm almost done, I just have a problem with one thing. I can't figure out how to mask a word. For example, if the word is monkey, the program should display ------ and as the user guess a letter, let's say k, the program should display ---k--</p>

<p>Unfortunately I have to write the code it certain way. I'm supposed to have a main function that will just call other functions that will do all the work (like functions that will ask user for a letter or check if the guessed word is correct). I have finished all the functions except for this masking function.</p>

<p>The function is called <code>maskWord(state, word, guess)</code>. I have to keep those variables, but they will be passed to the function. <code>state</code> is the masked word (eg.------),<code>word</code> is the word to be guessed (eg. monkey) and <code>guess</code> is the letter guessed by the user. Once the function updates the masked word, it should return <code>state</code>. The other rule is I can't create global variables. The variables that are passed are the ones that have to be used.</p>

<p>Here's what I have:</p>

<pre><code>def maskWord(state, word, guess)
  guessed = []
  guessed.append(guess)
  for guess in word:
    if guess in guessed:
      state += guess
    else: state += "-"
  return state
</code></pre>

<p>It doesn't really work. Because my main function that calls this function is a while loop, each time <code>guessed</code> becomes an empty string.</p>

<p>I would really appreciate it if someone could help me with this. I know that it has to be possible to write this function using only the variables, because my teacher only allowed to use those.</p>
