Python replace blanks
I want the letters the user types (granted that they're in the 'letters')
to replace the blanks in their correct sequential position (I don't want
'agbdf__'), and stop when all the letters are typed in. As the code is
now, it requires letters to be typed multiple times, and it stops if the
letter 'g' is typed seven times. If anyone could post the right way to
program this (not just a tip, because I most likely won't be able to
figure out how to implement it), it would be much appreciated.
letters='abcdefg'
blanks='_'*len(letters)
print('type letters from a to g')
print(blanks)
for i in range(len(letters)):
if letters[i] in input():
blanks = blanks[:i] + letters[i] + blanks[i+1:]
print(blanks)
No comments:
Post a Comment