Return the name of the hand in the following format: 'hand name, high card' Here are some examples: >>> PokerHand("KS AS TS QS JS").hand_name() 'Royal flush' >>> PokerHand("2D 6D 3D 4D 5D").hand_name() 'Straight flush, Six-high' >>>
(self)
| 185 | |
| 186 | # This function is not part of the problem, I did it just for fun |
| 187 | def hand_name(self) -> str: |
| 188 | """ |
| 189 | Return the name of the hand in the following format: |
| 190 | 'hand name, high card' |
| 191 | |
| 192 | Here are some examples: |
| 193 | >>> PokerHand("KS AS TS QS JS").hand_name() |
| 194 | 'Royal flush' |
| 195 | |
| 196 | >>> PokerHand("2D 6D 3D 4D 5D").hand_name() |
| 197 | 'Straight flush, Six-high' |
| 198 | |
| 199 | >>> PokerHand("JC 6H JS JD JH").hand_name() |
| 200 | 'Four of a kind, Jacks' |
| 201 | |
| 202 | >>> PokerHand("3D 2H 3H 2C 2D").hand_name() |
| 203 | 'Full house, Twos over Threes' |
| 204 | |
| 205 | >>> PokerHand("2H 4D 3C AS 5S").hand_name() # Low ace |
| 206 | 'Straight, Five-high' |
| 207 | |
| 208 | Source: https://en.wikipedia.org/wiki/List_of_poker_hands |
| 209 | """ |
| 210 | name = PokerHand._HAND_NAME[self._hand_type - 14] |
| 211 | high = PokerHand._CARD_NAME[self._high_card] |
| 212 | pair1 = PokerHand._CARD_NAME[self._first_pair] |
| 213 | pair2 = PokerHand._CARD_NAME[self._second_pair] |
| 214 | if self._hand_type in [22, 19, 18]: |
| 215 | return name + f", {high}-high" |
| 216 | elif self._hand_type in [21, 17, 15]: |
| 217 | return name + f", {pair1}s" |
| 218 | elif self._hand_type in [20, 16]: |
| 219 | join = "over" if self._hand_type == 20 else "and" |
| 220 | return name + f", {pair1}s {join} {pair2}s" |
| 221 | elif self._hand_type == 23: |
| 222 | return name |
| 223 | else: |
| 224 | return name + f", {high}" |
| 225 | |
| 226 | def _compare_cards(self, other: PokerHand) -> str: |
| 227 | # Enumerate gives us the index as well as the element of a list |
nothing calls this directly
no outgoing calls
no test coverage detected