Код: Выделить всё
import csv
import random
class Card:
FACES = ['2', '3', '4', '5', '6',
'7', '8', '9', '10', 'J', 'Q', 'K', 'A']
SUITS = ['♠', '♥', '♦', '♣']
def __init__(self, face, suit):
"""Initialize a Card with a face and suit."""
self._face = face
self._suit = suit
@property
def face(self):
"""Return the Card's self._face value."""
return self._face
@property
def suit(self):
"""Return the Card's self._suit value."""
return self._suit
@property
def image_name(self):
"""Return the Card's image file name."""
return str(self).replace(' ', '_') + '.png'
def __repr__(self):
"""Return string representation for repr()."""
return f"Card(face='{self.face}', suit='{self.suit}')"
def __str__(self):
"""Return string representation for str()."""
return f'{self.face} of {self.suit}'
def __format__(self, format):
"""Return formatted string representation."""
return f'{str(self):{format}}'
class DeckOfCards:
NUMBER_OF_CARDS = 52 # constant number of Cards
def __init__(self):
"""Initialize the deck."""
self._current_card = 0
self._deck = []
for count in range(DeckOfCards.NUMBER_OF_CARDS):
self._deck.append(Card(Card.FACES[count % 13],
Card.SUITS[count // 13]))
def shuffle(self):
"""Shuffle deck."""
self._current_card = 0
random.shuffle(self._deck)
def deal_card(self):
"""Return one Card."""
try:
card = self._deck[self._current_card]
self._current_card += 1
return card
except:
return None
def __str__(self):
"""Return a string representation of the current _deck."""
s = ''
for index, card in enumerate(self._deck):
s += f'{self._deck[index]:
Подробнее здесь: [url]https://stackoverflow.com/questions/78532910/str-object-has-no-attribute-suit[/url]