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


Groups > comp.lang.python > #51844

Re: Python: Code is ignoring the if and else

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Python: Code is ignoring the if and else
Date 2013-08-03 01:04 -0400
References <c6702eb3-494a-4359-84ef-d6679c09df35@googlegroups.com> <dfa6368b-565b-4512-8755-ef36fd2719cd@googlegroups.com> <b16bb894-a720-4e0c-a3ce-d699afffeb8e@googlegroups.com> <mailman.142.1375495945.1251.python-list@python.org> <0b558115-68c4-460b-863c-fef4b844bb57@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.146.1375506317.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 8/2/2013 10:24 PM, kevin4fong@gmail.com wrote:

Looking at this again, I believe you actually had the structure almost 
right before. You want to look through *all* of the target players cards 
and if *none* of them match, (ie the search fails), you want to draw 1 
card. What you were missing before is break or return

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")
              return True

       # else: needed if just break above, but not with return
		
       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]) + ">!!!")
           return True
        else:
            ShowMessage("MISS: You fished up the rank <" + 
str(top_card[0]) + ">")
            hit = hit - 1
            return False

The returns are based on what I remember of the rules from decades ago, 
that a hit either in the hand or the draw allowed another turn by the 
player.

-- 
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