# coins_dice_and_cards.py

import random

def flipCoin():
    return random.choice(['H', 'T'])

def flipCoins(times):
    result = [ ]
    for i in range(times):
        result.append(flipCoin())
    return result

def rollDie(sides=6):
    return random.randint(1, sides)

def rollDice(times, sides=6):
    result = [ ]
    for i in range(times):
        result.append(rollDie(sides))
    return result

def getUnshuffledDeck():
    deck = [ ]
    for suit in 'CDHS':
        for rank in 'A23456789TJQK':
            card = rank + suit
            deck.append(card)
    return deck

def getShuffledDeck():
    deck = getUnshuffledDeck()
    random.shuffle(deck)
    return deck

def testFlipCoin(totalFlips=10000):
    print('Testing flipCoin()...')
    flips = flipCoins(totalFlips)
    print('  totalFlips:', totalFlips)
    print('  first 100 flips:', flips[:100])
    print('  counts:')
    for result in 'HT':
        print('    ', result, ':', flips.count(result))
    print('  done')

def testRollDie(totalRolls=10000):
    print('Testing rollDie()...')
    rolls = rollDice(totalRolls)
    print('  totalRolls:', totalRolls)
    print('  first 100 rolls:', rolls[:100])
    print('  counts:')
    for side in range(1, 7):
        print('    ', side, ':', rolls.count(side))
    print('  done')

def testGetShuffledDeck():
    print('Testing getShuffledDeck()...')
    deck = getShuffledDeck()
    print('   Here is a shuffled deck:', deck)
    print('  done')

testFlipCoin()
testRollDie()
testGetShuffledDeck()
