-1
創建一個代表一副牌的類Deck
。你的班級應該有以下幾種方法:在Python中定義類
- 構造:按照標準順序創建一個52張卡組成的新卡組。
- shuffle:randomnizes卡的順序。
- dealCard:從甲板上方返回一張卡片並將卡片從甲板上移除
- cardsLeft:返回甲板上剩餘卡片的數量。
測試有它從一個洗牌的甲板,其中n
是用戶輸入交易出去的n
卡序列程序。
class Deck:
def __init__(self):
self.cardList=[]
for suit in ["d","c","h","s"]:
for rank in range(1,14):
card=PlayingCard(suit, rank)
self.cardList.append(card)
def shuffle(self):
#I DON'T KNOW HOW TO SHUFFLE MY CARDS PLEASE HELP.
#self.cardList[pos1] = self.cardList[pos2]
#self.cardList[pos2] = self.cardList[pos1]
#these two lines above are not working
def dealCard(self):
return self.cardList.pop()
def cardsLeft(self):
return len(self.cardList)
你的問題是什麼? – BrenBarn 2014-11-01 21:19:17
@BrenBarn根據埋在代碼中的意見,他們想知道如何洗牌。 – 2014-11-01 21:21:29
@Jess作業? – kums 2014-11-01 21:22:07