# Determining if Something is in Order

Page 1 of 1

## 4 Replies - 436 Views - Last Post: 04 December 2012 - 02:24 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=302649&amp;s=8bc3b528054d12af2b00f36244bb7688&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Stephenfrazier10

Reputation: 2
• 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

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

## Re: Determining if Something is in Order

Posted 03 December 2012 - 10:31 PM

Nevermind I got it!

### #3 Stephenfrazier10

Reputation: 2
• 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

```

### #4 Tayacan

• D.I.C Regular

Reputation: 145
• 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.

### #5 Stephenfrazier10

Reputation: 2
• 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