(allCards)
| 81 | |
| 82 | |
| 83 | def getHandValue(allCards): |
| 84 | value = 0 |
| 85 | numberOfAces = 0 |
| 86 | |
| 87 | # Add the value for the non-ace cards: |
| 88 | for card in allCards: |
| 89 | rank = card[0] # card is a list like [rank, suit] |
| 90 | if rank == 'A': |
| 91 | numberOfAces += 1 # Aces are worth at least 1. |
| 92 | elif rank in ['K', 'Q', 'J']: # Face cards are worth 10. |
| 93 | value += 10 |
| 94 | elif rank in ['2', '3', '4', '5', '6', '7', '8', '9', '10']: |
| 95 | value += int(rank) # Numbered cards are worth their number. |
| 96 | |
| 97 | # Add the value for the aces: |
| 98 | value += numberOfAces # Add 1 per ace. |
| 99 | for i in range(numberOfAces): |
| 100 | # If another 10 can be added without busting, do so: |
| 101 | if value + 10 <= 21: |
| 102 | value += 10 |
| 103 | |
| 104 | return value |
| 105 | |
| 106 | |
| 107 | def displayCards(allCards): |
no outgoing calls
no test coverage detected