Card Deck Class with Python
Card Deck Class using Python
This surprisingly short code will output the entire deck of playing cards with value and suite.
*Featured Code Submitted and Created by
VENOM666
Python
# Card deck class implementation
# by: VENOM666
class Card:
# List comprehension for card ranks (numbers) then add another list for high ranks
rank = [i for i in range(2,11)] + ["King", "Queen", "Jack", "Ace"]
suite = ["Hearts", "Diamonds", "Spades", "Clubs"]
deck = []
def __init__(self):
self.deck = [str(i) + " of " + s for i in self.rank for s in self.suite]
def deal(self):
for cards in self.deck:
print(cards)
c = Card()
c.deal()
Comments
Post a Comment