4 Replies - 363 Views - Last Post: 04 December 2012 - 02:24 AM Rate Topic: -----

#1 Stephenfrazier10  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 109
  • Joined: 12-September 12

Determining if Something is in Order

Posted 03 December 2012 - 09:38 PM

I have a function that is supposed to determine if the three values given are in order.
def InOrder(CardCollection):
    """
    Determines if a CardCollection is in order
    """
    a = int(CardCollection.cards[0].getFaceVal())
    b = int(CardCollection.cards[1].getFaceVal())
    c = int(CardCollection.cards[2].getFaceVal())
    if a <= b and b <= c: # If its in order from greatest to least
        return True
    elif c >= b and b >= a: # If its in order from least to greatest
        return True
    else:
        return False



It is supposed to determine if they are in either ascending order or descending order. If they are in order Player 1 is supposed to win, and if they're not Player 2 is supposed to win. But for some reason Player 2 wins every time, even if they are in order.
This is what I have at the after the order has been determined.
if InOrder(hand) == True:
            print(Player1 + " You win this play!")
            for i in range(3): # Adds the face value of the cards in hand to Player 1s total
                player1winTotal = player1winTotal + int(hand.cards[i].getFaceVal())
            for i in range(3): # Adds the cards to the wincards list
                player1wincards.append(hand.cards[i])
                
        else:
            print(Player2 + " Won this play!")



Is This A Good Question/Topic? 0
  • +

Replies To: Determining if Something is in Order

#2 Stephenfrazier10  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 109
  • Joined: 12-September 12

Re: Determining if Something is in Order

Posted 03 December 2012 - 10:31 PM

Nevermind I got it!
Was This Post Helpful? 0
  • +
  • -

#3 Stephenfrazier10  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 109
  • Joined: 12-September 12

Re: Determining if Something is in Order

Posted 03 December 2012 - 10:49 PM

Nevermind Again, it still does not work... I changed it to whats below, anyone have any idea how to make it always work?

def InOrder(CardCollection):
    """
    Determines if a CardCollection is in order
    """
    a = int(CardCollection.cards[0].getFaceVal())
    b = int(CardCollection.cards[1].getFaceVal())
    c = int(CardCollection.cards[2].getFaceVal())
    vallist = [a,b,c]
    if max(vallist) == vallist[2] and min(vallist) == vallist[0]: # If its in order least to greatest
        return True
    elif max(vallist) == vallist[0] and min(vallist) == vallist[2]: # If its in order greatest to least
        return True
    else:
        return False


Was This Post Helpful? 0
  • +
  • -

#4 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: Determining if Something is in Order

Posted 04 December 2012 - 02:06 AM

Yeah, okay, in the code you originally posted, I switched around a and c in line 10. For instance, in line 8, you ask if a is less than b. In line 10 you ask if b is greater than a. Instead, you need to ask if a is greater than b.
Was This Post Helpful? 1
  • +
  • -

#5 Stephenfrazier10  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 109
  • Joined: 12-September 12

Re: Determining if Something is in Order

Posted 04 December 2012 - 02:24 AM

Got it working now, Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1