0

I am trying to create a Class named poker that organizes the game poker. Right now, I am just creating a program that checks which hand you have. However, while doing this I saw that it is unnecessarily long, and I was wondering if it's possible to shorten it.

    def IsHighCard(self):
    if Poker.isStraightFlush is False and Poker.IsFourOfaKind is False and Poker.isFullHouse is False and Poker.IsFlush is False and Poker.IsStraight is False and Poker.isThreeOfaKind is False and Poker.IsTwoPairs is False and Poker.IsTwoPairs is False and Poker.IsOnePairs is False:
        return True
    else:
        return False

I have so many False statements, and I was wondering if there is a way to make them less redundant.
Also, when referencing a method in my class that is in another method, should I use Poker.IsOnePairs or Poker.IsOnePairs(self,hand).I'm not sure if I should include the parentheses.

PS: I don't see how that duplicate is relevant. The any() function only works for iterable, I'm not using iterable here.

momo123321
  • 147
  • 8
  • 2
    “ I'm not sure if I should include the parentheses.” You absolutely have to. Otherwise you are testing whether the method object itself is False which is never the case. – MisterMiyagi Dec 08 '22 at 06:51
  • 2
    "The any() function only works for iterable, I'm not using iterable here." You can put all of them into an iterable easily, though. For example `if not any([Poker.isStraightFlush, Poker.IsFourOfaKind, …])`. Note that it is currently difficult to say how to exactly rewrite this since every single comparison is likely wrong and we know neither what `self` nor `Poker` actually provides. – MisterMiyagi Dec 08 '22 at 07:05
  • okok, thank you, i will put them into a list. what do you mean by every single comparison is likely wrong – momo123321 Dec 08 '22 at 07:10
  • 1
    See my first comment. Assuming that `Poker` is a class the comparison `Poker.isStraightFlush is False` checks if the method object is identical to the `False` object. You likely want to check whether the result of calling the method on a specific `Poker` instance is `False` – that would be `not self.isStraightFlush`. – MisterMiyagi Dec 08 '22 at 07:13

0 Answers0