Replace blanks with letter
Peter Otten
__peter__ at web.de
Tue Aug 20 05:19:31 EDT 2013
eschneider92 at comcast.net wrote:
> I'm trying to replace the blank(_) with the letter typed in by the user,
> in the appropriate blank(_) spot where the letter should be (where is in
> the letters list).
>
> letters='abcdefg'
> blanks='_ '*len(letters)
> print('type letter from a to g')
> print(blanks)
> input1=input()
> for i in range(len(letters)):
> if letters[i] in input1:
> blanks = blanks[:i] + letters[i] + blanks[i+1:]
>
>
> What am I doing wrong in this code?
`blanks` has two chars per letter in `letters`. If you change the initial
value to
blanks = "_" * len(letters)
your code should work. If you think the output looks better with spaces you
have to adjust the indices -- or you add spaces for printing only with
print(" ".join(blanks))
More information about the Python-list
mailing list