Created
July 6, 2015 03:30
-
-
Save dean/99451d6e3579c7e24102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
types = ['Spades', 'Clubs', 'Hearts', 'Diamonds'] | |
num_to_name = {n: str(n) for n in range(2, 11)} | |
num_to_name.update({ | |
11: 'Jack', | |
12: 'Queen', | |
13: 'King', | |
14: 'Ace' | |
}) | |
card_str = '%s of %s' | |
gen_cards = lambda: [card_str % (num_to_name[n], type) for type in types for n in range(2,15)] | |
cards = gen_cards() | |
raw_input() | |
while True: | |
card = cards.pop(random.randint(0, len(cards) - 1)) | |
inp = raw_input('Next card: ' + card) | |
if inp == 'r': | |
if len(cards) == 0: | |
print 'Deck empty! Generating new...' | |
cards = gen_cards() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment