Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'subject:Python': 0.06; 'clause': 0.09; 'executed': 0.09; 'executes': 0.09; 'false.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; '8:40': 0.16; 'indent': 0.16; 'luckily': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'redundant': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'removed.': 0.24; 'subject:Code': 0.24; '(see': 0.26; 'player': 0.26; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'skip:p 30': 0.29; 'statement': 0.30; 'subject:the': 0.34; 'should': 0.36; 'so,': 0.37; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'delete': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'even': 0.60; 'received:173': 0.61; 'times': 0.62; 'email addr:gmail.com': 0.63; 'card': 0.63; 'believe': 0.68; 'line,': 0.68; 'below.': 0.71; 'received:fios.verizon.net': 0.84; 'ref': 0.84; 'subject:else': 0.84; 'rank': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python: Code is ignoring the if and else Date: Fri, 02 Aug 2013 21:42:30 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375494162 news.xs4all.nl 15884 [2001:888:2000:d::a6]:46388 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51835 Nonsense: they are executed just as you ask, even though what you ask is not what you meant. On 8/2/2013 8:40 PM, kevin4fong@gmail.com wrote: > def player_0_hitman(hit): > for card in pHands[target_player]: > if target_card[0] == card[0]: > count = pHands[target_player].count(card) > pHands[0].append(card) > pHands[target_player].remove(card) > ShowMessage("HIT: " + str(count) + " card(s) transferred") > else: else: # indent to match if > if target_card[0] != card[0]: # delete this if line, see below. > top_card = GetTopCard(sDeck) > pHands[0].append(top_card) > if top_card[0] == target_card[0]: > ShowMessage("HIT: LUCKILY Player 0 has fished up a rank <" + str(top_card[0]) + ">!!!") > else: > ShowMessage("MISS: You fished up the rank <" + str(top_card[0]) + ">") > hit = hit - 1 > return hit This executes the for loop multiple times and the the else: clause of the *for* statement (see the ref manual). I believe you want the whole else: clause indented so that it will be executed when the if condition is false. If so, the second if is redundant and should just be removed. -- Terry Jan Reedy