我正在学习 Python 并且正在构建纸牌游戏(似乎很常见并且对初学者来说很好)。我有一个名为打印随机卡的Cartas 方法的类。imprimir()然后我有一个名为的函数create_deck(),它用 52 张卡片填充一个空列表。
import random
class Cards:
def __init__(self, Value = random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13]),
Suit = random.choice(["Diamonds", "Hearts", "Clubs", "Spades"])):
self.Value = Value
self.Suit = Suit
def imprimir(self):
if self.Value == 11:
print("J of " + self.Suit)
elif self.Value == 12:
print("Queen of " + self.Suit)
elif self.Value == 13:
print("King of " + self.Suit)
else:
print(str(self.Value) + " de " + self.Suit)
card = Cards()
card.imprimir()
def create_deck():
list_deck = []
list_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
lista_suit = ["Diamonds", "Hearts", "Clubs", "Spades"]
for number in list_numbers:
for suit in list_suit :
if card == 11:
card = f'J of {suit}'
list_deck.append(card)
elif number == 12:
card = f'Queen of {suit}'
list_deck.append(card)
elif number == 13:
card = f'King of {suit}'
list_deck.append(card)
else:
card = f'{number} of {suit}'
list_deck.append(card)
print(list_deck)
print(create_deck())
我想create_deck()用 的新实例填充空列表,Cards()而不是只用字符串填充它,例如: [card1, card2, card3, etc etc,..card52]。
我怎样才能做到这一点?
呼唤远方
一只斗牛犬
相关分类