Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52732
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Replace blanks with letter |
| Date | 2013-08-20 11:19 +0200 |
| Organization | None |
| References | <2bdbd16f-a676-4973-9866-db93b1b9cd9b@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.55.1376990390.19984.python-list@python.org> (permalink) |
eschneider92@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))
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Replace blanks with letter eschneider92@comcast.net - 2013-08-20 01:35 -0700
Re: Replace blanks with letter Fábio Santos <fabiosantosart@gmail.com> - 2013-08-20 10:16 +0100
Re: Replace blanks with letter Peter Otten <__peter__@web.de> - 2013-08-20 11:19 +0200
Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-20 13:45 -0700
Re: Replace blanks with letter Dave Angel <davea@davea.name> - 2013-08-20 21:54 +0000
Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-21 00:49 -0700
Re: Replace blanks with letter Chris Angelico <rosuav@gmail.com> - 2013-08-21 19:24 +1000
Re: Replace blanks with letter Dave Angel <davea@davea.name> - 2013-08-21 11:42 +0000
Re: Replace blanks with letter John Gordon <gordon@panix.com> - 2013-08-21 14:35 +0000
Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-22 15:42 -0700
Re: Replace blanks with letter Dave Angel <davea@davea.name> - 2013-08-23 01:28 +0000
Re: Replace blanks with letter eschneider92@comcast.net - 2013-08-22 15:44 -0700
csiph-web