Poker hand string display

前端 未结 4 1678
后悔当初
后悔当初 2021-01-21 18:19

I\'m brand new to programming and Python and I\'m trying my hardest to understand and learn it. I\'m not asking for answers but explanations in plain non-computer terms so that

4条回答
  •  独厮守ぢ
    2021-01-21 19:11

    >>> def poker_card(c):
    ...     card, suit = c
    ...     short_cards = ['A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2']
    ...     short_suits = ['c', 'd', 'h', 's']
    ...     long_cards = ['ace', 'king', 'queen', 'jack', 'ten', 'nine', 'eight', 'seven', 'six',      'five', 'four', 'three', 'deuce']
    ...     long_suits = ['clubs', 'diamonds', 'hearts', 'spades']
    ...     return "%s of %s" % (long_cards[short_cards.index(card)], long_suits[short_suits.index(suit)])
    ... 
    >>> def poker_hand(hand):
    ...     return [poker_card(c) for c in hand]
    ... 
    >>> def main():
    ...     print poker_hand(["Kh", "As", "5d", "2c"])
    ... 
    >>> main()
    ['king of hearts', 'ace of spades', 'five of diamonds', 'deuce of clubs']
    

提交回复
热议问题