class HandOfCards:
def __init__ (self, numCardsInHand):
self.list = []
all_rank = random.randint(1, 13)
random_suit = ['d', 'c', 'h', 's']
all_suit = random.choice(random_suit)
for count in range(numCardsInHand):
self.list.append(Card(all_rank, all_suit))
def __str__(self):
all_items = '\n'.join(map(str, self.list))
return all_items
我想創造一些隨機的對象,但隨着循環如何創建隨機對象列表?
for count in range(numCardsInHand):
self.list.append(Card(all_rank, all_suit))
原來我真正創建完全相同的對象numCardsInHand
。看起來這個隨機模塊不適用於我的for
循環。我有問題搞清楚了。