Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'method.': 0.05; 'stops': 0.07; 'python': 0.09; 'arg': 0.09; 'behave': 0.09; 'suggest': 0.11; '*before*': 0.16; '24,': 0.16; 'egg': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'inclusive.': 0.16; 'integers,': 0.16; 'works...': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'integer': 0.17; 'thu,': 0.17; 'jan': 0.18; 'trying': 0.21; 'statement': 0.23; 'this:': 0.23; 'random': 0.24; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'values': 0.26; 'strongly': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'array': 0.29; 'point': 0.31; 'to:addr:python-list': 0.33; 'languages': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'but': 0.36; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'step': 0.39; 'think': 0.40; 'your': 0.60; 'range': 0.60; 'more': 0.63; 'skip:c 50': 0.66; "'for'": 0.84; '2013': 0.84; 'safer': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=ll3uxmdfRNEqDjvY/wdjx1kvAJbcwJ/FZEGw67RANRs=; b=tWn4WiXicAfLT/T5SLhS0r7kR6n50XcyHD6UZz20lnJ1MSOFaxDYh07I/tMC5vdV5+ DasSYdtnFul3nJohMS//Yked9nKm8mVmGkAVQtXA3JB4+Qyqi/VVGo5S/x6YMsh6b9ZP UwvFCRyMe/qB6Lk5p6xnXOQwsqsOJXWRTZh6kkSq5ONWd8pDQc6GhSnWZSOoQEIZhuL5 SSTMySbyLpiOGOq9NsrQKVYAb+krZ5bmChUlZ/0y23mBuUHev8LKmhAfwCczSqbmhCLP SuEySq/eRqwdim7L7HZmMUDSfHNr9hqoK3KWYXr+owrZtqh4pSa03tTyOn/fZ0Z60B42 X8iA== MIME-Version: 1.0 X-Received: by 10.68.234.229 with SMTP id uh5mr1599264pbc.123.1359003553964; Wed, 23 Jan 2013 20:59:13 -0800 (PST) In-Reply-To: <7694aab5-7926-482e-975a-7685c7b94351@googlegroups.com> References: <7694aab5-7926-482e-975a-7685c7b94351@googlegroups.com> Date: Thu, 24 Jan 2013 15:59:13 +1100 Subject: Re: Decrease for loop by one From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359003563 news.xs4all.nl 6862 [2001:888:2000:d::a6]:37075 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37536 On Thu, Jan 24, 2013 at 3:39 PM, Milter Skyler wrote: > I made an array to check if the random integer already exists and then I send it to the else statement at which point I want to decrease x by 1 so that it doesn't count as one of the loops. In other languages this works... A Python 'for' loop doesn't behave like that; you can't just edit the loop counter. But take a step back: what are you actually trying to accomplish? As I see it, you're trying to pick ten unique random values in the range 1-12 inclusive. Try this: random.sample(range(1,13),10) # note that range() stops *before* its second arg That'll give you a list of those integers, and it's a lot safer and more reliable than the try-fail-retry method. Your loop can become: for decimal_value in random.sample(range(1,13),10): egg = 'A%d.png' % (decimal_value) egg = wait(egg) click(egg.getCenter().offset(random.randint(-10,10), random.randint(-10,10))) By the way, this line simply won't work: x-1 = x I think you mean: x = x-1 But I strongly suggest you copy and paste directly rather than retype; it's less error-prone. Hope that helps! ChrisA