Instead of using letters as substitutes for playing card suits, I came up with a way to use unicodes to produce the common suits. The following creates the coded needed, makes the deck, and then prints the deck. The printing was the hard part. Is 2.7, and should be 3.0+ compat.
Using Unicode to Produce Better Looking Cards and Decks
# Imports #
from __future__ import print_function
# Main #
def main():
# Main Code
# Create Deck of Cards
v_Deck = f_CreateDeck() ## Create deck of cards.
print("DEBUG", "Deck") # DEBUG
f_PrintDeck(v_Deck) # DEBUG
def f_CreateDeck():
"""Creates the card deck of 13 cards, 2 > A, of each of 4 suits
None, Return(string list)"""
v_Deck = [] ## Init deck variable
for i in [u"u2663", u"u2660", u"u2666", u"u2665"]: ## Each suit: Clubs, Spades, Diamonds, Hearts
for j in xrange(2, 11): ## Numbered cards
v_Deck.append(str(j) + i) ## Append each number to a suit
for j in ("J", "Q", "K", "A"): ## Face cards
v_Deck.append(str(j) + i) ## Append each face card to a suit
return v_Deck
# DEBUG PRINT DECK OF CARDS
def f_PrintDeck(v_Deck):
v_RowCount, v_CardCount = 0, 0 ## Init row count, and card count
v_LenLine = 13 ## Init typical line length
v_NumLines, v_LenLastLine = divmod(len(v_Deck), v_LenLine) ## Get this deck's computed num of lines, and the length of the last line
for i in xrange(0, (v_NumLines + 1)):
if v_RowCount == (v_NumLines): ## If at last line change length of line to computed value of last line
v_LenLine = v_LenLastLine
for j in xrange(v_LenLine): ## Run through printing each value to max of line length
print((v_Deck[v_CardCount]), end = ",")
v_CardCount += 1 ## Increment card count
print() ## Advance to next line
v_RowCount += 1 ## Increment row
return
main()
Gribouillis 1,391 Programming Explorer Team Colleague
BustACode commented: System won't let me post as "snippet," only discussion. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Gribouillis 1,391 Programming Explorer Team Colleague
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
fonzali 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.