MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / getRandomCard

Function getRandomCard

src/gamesbyexample/threecardmonte.py:46–54  ·  view source on GitHub ↗

Returns a random card that is NOT the Queen of Hearts.

()

Source from the content-addressed store, hash-verified

44
45
46def 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
57print('Three-Card Monte, by Al Sweigart al@inventwithpython.com')

Callers 1

threecardmonte.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected