在底部,我创建一个牌组然后发起一个玩家。然后我尝试用draw_card()绘制一张卡片并打印出来。而不是卡,我得到'没'。有人可以解释一下原因吗?这是我创建类的第一个项目,这应该是一个快速的实践和改进的程序;所以我是新手,可能会犯很多新手错误。这是代码。
import random
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'jack', 'queen', 'king', 'ace']
suits = ['hearts', 'diamonds', 'clubs', 'spades']
deck = []
class Card:
def __init__(self):
pass
# print the current card
def __str__(self):
print(f'{numbers} of {suits}')
class Deck(Card):
def __init__(self):
super().__init__()
# create a new deck of cards
def create_deck(self):
for suit in suits:
for number in numbers:
deck.append([number, suit])
return deck
# shuffle the deck of cards before the start of the game
def shuffle_deck(self):
random.shuffle(deck)
return deck
class Player(Deck):
def __init__(self):
super().__init__()
self.hand = []
self.count_cards = 0
self.score = 0
# draw a card from the deck
def draw_card(self):
drawn_card = self.hand.append(deck[-1])
print(drawn_card)
# count the cards in the players hand
def count_hand(self):
self.count_cards = len(self.hand)
print(self.count_cards)
# calculate the score each time the player wins
def calculate_score(self):
pass
d = Deck()
d.create_deck()
d.shuffle_deck()
ezekiel = Player()
ezekiel.draw_card()
ezekiel.count_hand()