Returns a random card that is NOT the Queen of Hearts.
()
| 44 | |
| 45 | |
| 46 | def getRandomCard(): |
| 47 | """Returns a random card that is NOT the Queen of Hearts.""" |
| 48 | while True: # Make cards until you get a non-Queen of hearts. |
| 49 | rank = random.choice(list('23456789JQKA') + ['10']) |
| 50 | suit = random.choice([HEARTS, DIAMONDS, SPADES, CLUBS]) |
| 51 | |
| 52 | # Return the card as long as it's not the Queen of Hearts: |
| 53 | if rank != 'Q' and suit != HEARTS: |
| 54 | return (rank, suit) |
| 55 | |
| 56 | |
| 57 | print('Three-Card Monte, by Al Sweigart al@inventwithpython.com') |