Skip to content

Instantly share code, notes, and snippets.

@dean
Created July 6, 2015 03:30
Show Gist options
  • Save dean/99451d6e3579c7e24102 to your computer and use it in GitHub Desktop.
Save dean/99451d6e3579c7e24102 to your computer and use it in GitHub Desktop.
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':
print
if len(cards) == 0:
print 'Deck empty! Generating new...'
print
print
cards = gen_cards()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment