Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'received:209.85.214.174': 0.13; 'cc:addr:python-list': 0.15; '0))': 0.16; '255': 0.16; '3),': 0.16; 'seconds,': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.16; 'trying': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply- To:1': 0.22; 'figure': 0.23; 'thus': 0.23; 'cc:2**0': 0.25; 'code': 0.25; 'seconds': 0.25; 'code,': 0.27; 'message- id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'skip:\xc2 20': 0.30; 'received:209.85.214': 0.32; 'instead': 0.33; 'hi,': 0.34; 'routine': 0.34; 'something': 0.35; 'run': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'screen': 0.38; 'should': 0.38; "couldn't": 0.39; 'received:209': 0.39; 'expected': 0.39; 'subject:: ': 0.39; '8bit%:8': 0.40; 'skip:\xc2 10': 0.74; 'respectively': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=m7pnrEXF6h+SrhjDiNnW84f2QVckJkDf5WJMlnLf8aw=; b=hViA5vM5t+xhLC0vqARQ0MDF+g64fcwRmI9k4daCPtiJQSV5xyjC8yiijAYAJBRWH6 R3o1xADpzS7QV+r4pPEyqpuuhpKqrYLZS8EpumxuwUfk8gl4hnbtVnbY3RuBBcubVdjx qR2XhNQea7EvOwTKA/X2vLq3odd99EjhHo+Gk= MIME-Version: 1.0 In-Reply-To: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> References: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> Date: Fri, 20 Jan 2012 23:10:44 +0000 Subject: Re: Weird Loop Behaviour From: Arnaud Delobelle To: Yigit Turgut Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327101047 news.xs4all.nl 6982 [2001:888:2000:d::a6]:32815 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19173 On 20 January 2012 20:47, Yigit Turgut wrote: > Hi, > > In the following code, I am trying to run "black" screen for 3 seconds > and respectively 2 seconds "white" screen. Black routine takes 3 > seconds and white 2 seconds, 2 x black + white =3D 8 seconds which > should be the expected value but when I run it I get black-white-black- > white =C2=A0 instead of black-white-black. Couldn't figure out what is > wrong thus sharing the code as well ; > > white =3D False > =C2=A0 =C2=A0 while(end<8.00): > =C2=A0 =C2=A0 =C2=A0end =3D time.time() - start > =C2=A0 =C2=A0 =C2=A0if white: > =C2=A0 =C2=A0 =C2=A0 screen.fill((255, 255, 255)) > =C2=A0 =C2=A0 =C2=A0 =C2=A0time.sleep(2) > =C2=A0 =C2=A0 =C2=A0else: > =C2=A0 =C2=A0 =C2=A0 =C2=A0screen.fill((0, 0, 0)) > =C2=A0 =C2=A0 =C2=A0 =C2=A0time.sleep(3) > =C2=A0 =C2=A0 =C2=A0white =3D not white > =C2=A0 =C2=A0 =C2=A0pygame.display.update() > =C2=A0 =C2=A0 pygame.quit() This is cryptic. You'd be better off with something like black =3D 0, 0, 0 white =3D 255, 255, 255 for color, wait in (black, 3), (white, 2), (black, 3): screen.fill(color) pygame.display.update() time.sleep(wait) pygame.quit() --=20 Arnaud