Im trying to make a card class that I can use in other programs, the main goal of this is to make a deck of cards that would be valid, only 52 cards - no repeats, 4 suits - 13 cards each. My problem is I don't know how to work out the loops or any mechanism for testing what has already been drawn and then removing or only drawing different cards after that. Any help would be appreciated.
from random import *
from graphics import *
class DeckOfCards:
def __init__(self):
"""Make a deck of cards with variables rank, suit and value"""
self.rank = None
self.suit = None
self.value = None
def getRank(self):
return self.rank
def getSuit(self):
return self.suit
def getValue(self):
return self.value
def RandomCard(self):
"""Test a card to see if its a valid draw"""
self.PossCards=["1","2","3","4","5","6","7","8","9","10","j","q","k"]
self.PossSuit = ["h","s","d","c"]
rankCount=[0]*13
cardCount,hearts,spades,diamonds,clubs=0,0,0,0,0
while cardCount<53:
cardCount+=1
while self.PossCards:
self.value = randrange(0,len(self.PossCards))+1
self.rank = self.PossCards[self.value-1]
rankCount[self.value-1]+=1
for x in range(len(rankCount)):
print(rankCount)
if rankCount[x]>4:
rem=str(rankCount[x])
self.PossCards.remove(rem)
while self.PossSuit:
self.suit = self.PossSuit[randrange(0,len(self.PossSuit))]
if self.suit=="h":
hearts+=1
if hearts>12:
self.PossSuit.remove("h")
elif self.suit=="s":
spades+=1
self.PossSuit.remove("s")
elif self.suit=="d":
diamonds+=1
if diamonds>12:
self.PossSuit.remove("d")
else:
clubs+=1
if clubs>12:
self.PossSuit.remove("c")