Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'from:addr:python': 0.09; '0))': 0.16; '_after_': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply- to:addr:python-list': 0.16; 'seconds,': 0.16; "would've": 0.16; 'wrote:': 0.16; 'simpler': 0.18; 'trying': 0.20; 'header:In-Reply- To:1': 0.22; 'figure': 0.23; 'thus': 0.23; 'code': 0.25; 'seconds': 0.25; 'testing': 0.26; 'code,': 0.27; 'header:User- Agent:1': 0.33; 'instead': 0.33; 'to:addr:python-list': 0.33; 'it?': 0.33; 'received:84': 0.34; 'hi,': 0.34; 'setting': 0.34; 'reply-to:addr:python.org': 0.34; 'routine': 0.34; 'run': 0.37; 'but': 0.37; 'could': 0.37; 'screen': 0.38; 'should': 0.38; "couldn't": 0.39; 'expected': 0.39; 'subject:: ': 0.39; 'might': 0.40; 'to:addr:python.org': 0.40; 'as:': 0.70; 'header:Reply- To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'respectively': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=A/buztqG c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=FFsdPcU1_MIA:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=16Y6A9kP5WGxh-Sv7oYA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Fri, 20 Jan 2012 21:10:29 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Weird Loop Behaviour References: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> In-Reply-To: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327093827 news.xs4all.nl 6866 [2001:888:2000:d::a6]:50690 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19167 On 20/01/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 = 8 seconds which > should be the expected value but when I run it I get black-white-black- > white instead of black-white-black. Couldn't figure out what is > wrong thus sharing the code as well ; > > white = False > while(end<8.00): > end = time.time() - start > if white: > screen.fill((255, 255, 255)) > time.sleep(2) > else: > screen.fill((0, 0, 0)) > time.sleep(3) > white = not white > pygame.display.update() > pygame.quit() Could it be because you're setting 'end' after testing it? It might be simpler as: while time.time() - start < 8: Also, should it really be sleeping before updating the display? I would've thought that it should be sleeping _after_ updating the display.