Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'assignment': 0.07; 'string': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'typed': 0.09; 'random': 0.14; 'email addr:comcast.net': 0.16; 'enough.': 0.16; 'goal,': 0.16; 'heed': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'thanks.': 0.20; 'code,': 0.22; 'example': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'stick': 0.24; 'post': 0.26; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'related': 0.29; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'bunch': 0.31; 'end,': 0.31; 'anyone': 0.31; 'figure': 0.32; 'run': 0.32; 'running': 0.33; '(most': 0.33; 'guess': 0.33; 'not.': 0.33; 'maybe': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'problem': 0.35; 'subject:with': 0.35; "can't": 0.35; 'advice': 0.35; 'test': 0.35; 'but': 0.35; 'doing': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; "i'll": 0.36; 'clear': 0.37; 'implement': 0.38; 'problems': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'future': 0.60; 'letters': 0.60; 'tell': 0.60; "you're": 0.61; 'times': 0.62; 'fact,': 0.69; 'wish': 0.70; 'homework': 0.84; 'subject:letter': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Replace blanks with letter Date: Wed, 21 Aug 2013 11:42:24 +0000 (UTC) References: <2bdbd16f-a676-4973-9866-db93b1b9cd9b@googlegroups.com> <89146bb1-fb60-4746-93e2-6cb59cfbc432@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 174.32.174.30 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377085363 news.xs4all.nl 15917 [2001:888:2000:d::a6]:46128 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52764 eschneider92@comcast.net wrote: > Thanks. I am running into a bunch of problems with the following code, all of which are clear when running the program > > import random > 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) > > If anyone could post an example of how to correctly code this, I would appreciate it. I can't seem to figure it out. > > I'll definitely heed Fabio's advice for future reference, but I don't think it's related to the problems I'm currently experiencing. If it is, and I'm just not getting it (most likely the case), please post an example of how to implement his code advice in doing what I wish to accomplish here. Nowhere have you told us just what the homework assignment was. Depending on the goal, this could be "fixed" in various ways. As it stands, you are asking the user 7 times to type in the letters from a to g. So long as he responds each time the same way, it'll gradually fill in the letters from left to right, and end up with all seven showing. In fact, it'll do that even if the user just types the particular single letter you're asking for. So in my last response below, I typed a string that didn't have all 7, but it did have a g, so that was good enough. davea@think2:~/temppython$ python3.3 eric.py type letters from a to g _______ abcdefg a______ abcdefg ab_____ abcdefg abc____ abcdefg abcd___ abcdefg abcde__ agcdbfe abcdef_ aggecca abcdefg davea@think2:~/temppython$ Maybe the problem is that you don't tell the user whether he has succeeded or not. To tell that, just stick a test at the end, outside the for-loop. if blanks == letters: print("Good job") else: print("You lose, run again, and guess what I wanted") -- DaveA