Всех приветствую. Разбираю тему классов и наследования в Python. Возникла ошибка TypeError: Deck.shuffle() missing 1 required positional argument: 'self'. Не могу разобраться в чём причина ошибки. Подскажите, пожалуйста, что не так.
class Card:
suits = ["Clubs", "Diamonds", "Hearts", "Spades"]
ranks = ["narf", "Ace", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "Jack", "Queen", "King"]
def __init__(self, suit=0, rank=0):
self.suit = suit
self.rank = rank
def __str__(self):
return (self.ranks[self.rank] + " of " +
self.suits[self.suit])
def __cmp__(self, other):
# check the suits
if self.suit > other.suit: return 1
if self.suit < other.suit: return -1
# suits are the same... check rankse
if self.rank == 1 and other.rank == 13: return 1
elif self.rank > other.rank: return 1
elif self.rank < other.rank: return -1
# ranks are the same... its a tie
return 0
class Deck:
def __init__(self):
self.cards = []
for suit in range(4):
for rank in range(1, 14):
self.cards.append(Card(suit, rank))
def __str__(self):
s = ''
for i in range(len(self.cards)):
s = s + ''*i + str(self.cards[i]) + '\n'
return s
def shuffle(self):
import random
num_cards = len(self.cards)
for i in range(num_cards):
j = random.randint(i, num_cards)
self.cards[i], self.cards[j] = self.cards[j], self.cards[i]
def remove(self):
if card in self.cards:
self.cards.remove(card)
return True
else:
return False
def pop(self):
return self.cards.pop()
def is_empty(self):
return (len(self.cards) == 0)
def deal(self, hands, num_cards):
num_hands = len(hands)
for i in range(num_cards):
if self.is_empty(): break # break if out of cards
card = self.pop() # take the top card
hand = hands[i % num_hands] # whose turn is next?
hand.add(card) # add the carcd to the hand
class Hand(Deck):
def __init__(self, name=" "):
super().__init__()
self.name = name
self.cards = []
def add(self, card):
self.cards.append(card)
deck = Deck
deck.shuffle()
hand = Hand("Frank")
deck.deal([hand], 5)
print(hand)
Из этого получаю ошибку: TypeError: Deck.shuffle() missing 1 required positional argument: 'self'