Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51835

Re: Python: Code is ignoring the if and else

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 <python-python-list@m.gmane.org>
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 <tjreedy@udel.edu>
Subject Re: Python: Code is ignoring the if and else
Date Fri, 02 Aug 2013 21:42:30 -0400
References <c6702eb3-494a-4359-84ef-d6679c09df35@googlegroups.com>
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 <c6702eb3-494a-4359-84ef-d6679c09df35@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.140.1375494162.1251.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 17:40 -0700
  Re: Python: Code is ignoring the if and else MRAB <python@mrabarnett.plus.com> - 2013-08-03 02:38 +0100
  Re: Python: Code is ignoring the if and else John Ladasky <john_ladasky@sbcglobal.net> - 2013-08-02 18:39 -0700
    Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 18:44 -0700
      Re: Python: Code is ignoring the if and else Chris Angelico <rosuav@gmail.com> - 2013-08-03 02:56 +0100
      Re: Python: Code is ignoring the if and else Joshua Landau <joshua@landau.ws> - 2013-08-03 03:11 +0100
        Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 19:24 -0700
          Re: Python: Code is ignoring the if and else Terry Reedy <tjreedy@udel.edu> - 2013-08-03 01:04 -0400
            Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-03 13:12 -0700
  Re: Python: Code is ignoring the if and else Terry Reedy <tjreedy@udel.edu> - 2013-08-02 21:42 -0400
    Re: Python: Code is ignoring the if and else kevin4fong@gmail.com - 2013-08-02 18:46 -0700
  Re: Python: Code is ignoring the if and else Dave Angel <davea@davea.name> - 2013-08-03 03:34 +0000

csiph-web