Reputation: 1943
I'm attempting to arrange the following code so that a digit representing the character place in the word appears below the mask. In other words:
_ _ _
1 2 3
Here's my current code:
secretWord = 'dog'
mask = '_' * len(secretWord)
for i in range (len(secretWord)):
if secretWord[i] in correctLetters:
mask = mask[:i] + secretWord[i] + mask [i+1:]
for letter in mask:
print (letter, end='')
print ()
How would I go about this?
Upvotes: 1
Views: 5051
Reputation: 114035
A list representation would help you out here:
secretWord = list('dog') # ['d', 'o', 'g']
mask = ['_'] * len(secretWord) # not problematic, since strs are immutable
for i,char in enumerate(secretWord):
if secretWord[i] in correctLetters:
mask[i] = secretWord[i]
print (''.join(mask))
Hope this helps
Upvotes: 1