Решение на Тесте карти от Елена Димитрова

Обратно към всички решения

Към профила на Елена Димитрова

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 16 успешни тест(а)
  • 0 неуспешни тест(а)

Код

class Rank:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return isinstance(self, other.__class__)
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return isinstance(self, other.__class__)
class Ace(Rank):
symbol = '1'
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Hearts(Suit):
color = 'red'
class Diamonds(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
RANKS = {"Ace": Ace, "Two": Two, "Three": Three, "Four": Four,
"Five": Five, "Six": Six, "Seven": Seven, "Eight": Eight,
"Nine": Nine, "Ten": Ten, "Jack": Jack, "Queen": Queen,
"King": King}
SUITS = {"Hearts": Hearts, "Spades": Spades,
"Diamonds": Diamonds, "Clubs": Clubs}
class Card:
def __init__(self, rank, suit):
self._card = (rank(), suit())
@property
def rank(self):
return self._card[0]
@property
def suit(self):
return self._card[1]
def __str__(self):
return str(self.rank) + " of " + str(self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection = []):
self._cards = []
for card in collection:
self._cards.append(card)
def draw(self, index):
return self._cards.pop(index)
def draw_from_top(self):
return self._cards.pop(len(self._cards) - 1)
def draw_from_bottom(self):
return self._cards.pop(0)
def top_card(self):
return self._cards[len(self._cards) - 1]
def bottom_card(self):
return self._cards[0]
def add(self, card):
self._cards.append(card)
def index(self, card):
return self._cards.index(card)
def __getitem__(self, index):
return self._cards[index]
def __len__(self):
return len(self._cards)
def StandardDeck():
ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
"Six", "Five", "Four", "Three", "Two", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck
def BeloteDeck():
ranks = ["King", "Queen", "Jack", "Ten",
"Nine", "Eight", "Seven", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck
def SixtySixDeck():
ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck

Лог от изпълнението

................
----------------------------------------------------------------------
Ran 16 tests in 0.018s

OK

История (3 версии и 1 коментар)

Елена обнови решението на 22.03.2014 18:13 (преди около 10 години)

+class Rank:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return isinstance(self, other.__class__)
+
+
+class Suit:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return isinstance(self, other.__class__)
+
+
+class Ace(Rank):
+ symbol = '1'
+
+
+class Two(Rank):
+ symbol = '2'
+
+
+class Three(Rank):
+ symbol = '3'
+
+
+class Four(Rank):
+ symbol = '4'
+
+
+class Five(Rank):
+ symbol = '5'
+
+
+class Six(Rank):
+ symbol = '6'
+
+
+class Seven(Rank):
+ symbol = '7'
+
+
+class Eight(Rank):
+ symbol = '8'
+
+
+class Nine(Rank):
+ symbol = '9'
+
+
+class Ten(Rank):
+ symbol = '10'
+
+
+class Jack(Rank):
+ symbol = 'J'
+
+
+class Queen(Rank):
+ symbol = 'Q'
+
+
+class King(Rank):
+ symbol = 'K'
+
+
+class Hearts(Suit):
+ color = 'red'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+
+class Spades(Suit):
+ color = 'black'
+
+
+class Clubs(Suit):
+ color = 'black'
+
+RANKS = {"Ace": Ace, "Two": Two, "Three": Three, "Four": Four,
+ "Five": Five, "Six": Six, "Seven": Seven, "Eight": Eight,
+ "Nine": Nine, "Ten": Ten, "Jack": Jack, "Queen": Queen,
+ "King": King}
+
+SUITS = {"Hearts": Hearts, "Spades": Spades,
+ "Diamonds": Diamonds, "Clubs": Clubs}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self._card = (rank(), suit())
+
+ @property
+ def rank(self):
+ return self._card[0]
+
+ @property
+ def suit(self):
+ return self._card[1]
+
+ def __str__(self):
+ return str(self.rank) + " of " + str(self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self._cards = []
+ for card in collection:
+ self._cards.append(card)
+
+ def draw(self, index):
+ return self._cards.pop(index)
+
+ def draw_from_top(self):
+ return self._cards.pop(0)
+
+ def draw_from_bottom(self):
+ return self._cards.pop(len(self._cards) - 1)
+
+ def top_card(self):
+ return self._cards[len(self._cards) - 1]
+
+ def bottom_card(self):
+ return self._cards[0]
+
+ def add(self, card):
+ self._cards.append(card)
+
+ def index(self, card):
+ return self._cards.index(card)
+
+ def __getitem__(self, index):
+ return self._cards[index]
+
+
+def StandartDeck():
+ ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
+ "Six", "Five", "Four", "Three", "Two", "Ace"]
+ suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
+ deck = []
+ for suit in suits:
+ for rank in ranks:
+ card = Card(RANKS[rank], SUITS[suit])
+ deck.append(str(card))
+ return deck
+
+
+def BeloteDeck():
+ ranks = ["King", "Queen", "Jack", "Ten",
+ "Nine", "Eight", "Seven", "Ace"]
+ suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
+ deck = []
+ for suit in suits:
+ for rank in ranks:
+ card = Card(RANKS[rank], SUITS[suit])
+ deck.append(str(card))
+ return deck
+
+
+def SixtySixDeck():
+ ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Ace"]
+ suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
+ deck = []
+ for suit in suits:
+ for rank in ranks:
+ card = Card(RANKS[rank], SUITS[suit])
+ deck.append(str(card))
+ return deck

Елена обнови решението на 23.03.2014 17:29 (преди около 10 години)

class Rank:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return isinstance(self, other.__class__)
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return isinstance(self, other.__class__)
class Ace(Rank):
symbol = '1'
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Hearts(Suit):
color = 'red'
class Diamonds(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
RANKS = {"Ace": Ace, "Two": Two, "Three": Three, "Four": Four,
"Five": Five, "Six": Six, "Seven": Seven, "Eight": Eight,
"Nine": Nine, "Ten": Ten, "Jack": Jack, "Queen": Queen,
"King": King}
SUITS = {"Hearts": Hearts, "Spades": Spades,
"Diamonds": Diamonds, "Clubs": Clubs}
class Card:
def __init__(self, rank, suit):
self._card = (rank(), suit())
@property
def rank(self):
return self._card[0]
@property
def suit(self):
return self._card[1]
def __str__(self):
return str(self.rank) + " of " + str(self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
- def __init__(self, collection):
+ def __init__(self, collection = []):
self._cards = []
for card in collection:
self._cards.append(card)
def draw(self, index):
return self._cards.pop(index)
def draw_from_top(self):
return self._cards.pop(0)
def draw_from_bottom(self):
return self._cards.pop(len(self._cards) - 1)
def top_card(self):
return self._cards[len(self._cards) - 1]
def bottom_card(self):
return self._cards[0]
def add(self, card):
self._cards.append(card)
def index(self, card):
return self._cards.index(card)
def __getitem__(self, index):
return self._cards[index]
-def StandartDeck():
+def StandardDeck():
ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
"Six", "Five", "Four", "Three", "Two", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck
def BeloteDeck():
ranks = ["King", "Queen", "Jack", "Ten",
"Nine", "Eight", "Seven", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck
def SixtySixDeck():
ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck

Елена обнови решението на 25.03.2014 23:23 (преди около 10 години)

class Rank:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return isinstance(self, other.__class__)
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return isinstance(self, other.__class__)
class Ace(Rank):
symbol = '1'
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Hearts(Suit):
color = 'red'
class Diamonds(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
RANKS = {"Ace": Ace, "Two": Two, "Three": Three, "Four": Four,
"Five": Five, "Six": Six, "Seven": Seven, "Eight": Eight,
"Nine": Nine, "Ten": Ten, "Jack": Jack, "Queen": Queen,
"King": King}
SUITS = {"Hearts": Hearts, "Spades": Spades,
"Diamonds": Diamonds, "Clubs": Clubs}
class Card:
def __init__(self, rank, suit):
self._card = (rank(), suit())
@property
def rank(self):
return self._card[0]
@property
def suit(self):
return self._card[1]
def __str__(self):
return str(self.rank) + " of " + str(self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection = []):
self._cards = []
for card in collection:
self._cards.append(card)
def draw(self, index):
return self._cards.pop(index)
def draw_from_top(self):
- return self._cards.pop(0)
+ return self._cards.pop(len(self._cards) - 1)
def draw_from_bottom(self):
- return self._cards.pop(len(self._cards) - 1)
+ return self._cards.pop(0)
def top_card(self):
return self._cards[len(self._cards) - 1]
def bottom_card(self):
return self._cards[0]
def add(self, card):
self._cards.append(card)
def index(self, card):
return self._cards.index(card)
def __getitem__(self, index):
return self._cards[index]
+ def __len__(self):
+ return len(self._cards)
def StandardDeck():
ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
"Six", "Five", "Four", "Three", "Two", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck
def BeloteDeck():
ranks = ["King", "Queen", "Jack", "Ten",
"Nine", "Eight", "Seven", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck
def SixtySixDeck():
ranks = ["King", "Queen", "Jack", "Ten", "Nine", "Ace"]
suits = ["Diamonds", "Clubs", "Hearts", "Spades"]
deck = []
for suit in suits:
for rank in ranks:
card = Card(RANKS[rank], SUITS[suit])
deck.append(str(card))
return deck