Решение на Тесте карти от Велина Дойчева

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

Към профила на Велина Дойчева

Резултати

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

Код

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.__class__.__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
RANKS = {x.__name__: x for x in Rank.__subclasses__()}
SUITS = {x.__name__: x for x in Suit.__subclasses__()}
RANK_ORDER = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
SUIT_ORDER = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class Card(Rank, Suit):
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __setattr__(self, attr, value):
if hasattr(self, attr):
raise AttributeError("Attribute already has a value")
else:
self.__dict__[attr] = value
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return("{0} of {1}".format(self.rank, self.suit))
def __repr__(self):
return("<Card {0}>".format(self))
class CardCollection:
def __init__(self, collection=[]):
self.collection = []
for i in collection:
self.collection.append(i)
def __getitem__(self, i):
return self.collection[i]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
return self.collection.index(card)
def StandardDeck():
deck = CardCollection()
for suit in SUIT_ORDER:
for rank in RANK_ORDER:
deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)
def BeloteDeck():
excluded = ['Two', 'Three', 'Four', 'Five', 'Six']
belote_ranks = [rank for rank in RANK_ORDER if rank not in excluded]
deck = CardCollection()
for suit in SUIT_ORDER:
for rank in belote_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)
def SixtySixDeck():
excluded = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
sixty_six_ranks = [rank for rank in RANK_ORDER if rank not in excluded]
deck = CardCollection()
for suit in SUIT_ORDER:
for rank in sixty_six_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.027s

OK

История (4 версии и 0 коментара)

Велина обнови решението на 26.03.2014 16:03 (преди над 10 години)

+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+
+RANKS = {x.__name__: x for x in Rank.__subclasses__()}
+SUITS = {x.__name__: x for x in Suit.__subclasses__()}
+
+
+class Card(Rank, Suit):
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __setattr__(self, attr, value):
+ if hasattr(self, attr):
+ raise AttributeError("Attribute already has a value")
+ else:
+ self.__dict__[attr] = value
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return("{0} of {1}".format(self.rank, self.suit))
+
+ def __repr__(self):
+ return("{0} of {1}".format(self.rank, self.suit))
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = []
+ for i in collection:
+ self.collection.append(i)
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+ def __iter__(self):
+ return iter(self.collection)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def index(self, card):
+ return self.collection.index(card)
+
+
+def StandardDeck():
+ deck = CardCollection()
+ for suit in SUITS.values():
+ for rank in RANKS.values():
+ deck.add(Card(rank, suit))
+ return deck

Велина обнови решението на 26.03.2014 16:34 (преди над 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.__class__.__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
RANKS = {x.__name__: x for x in Rank.__subclasses__()}
SUITS = {x.__name__: x for x in Suit.__subclasses__()}
class Card(Rank, Suit):
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __setattr__(self, attr, value):
if hasattr(self, attr):
raise AttributeError("Attribute already has a value")
else:
self.__dict__[attr] = value
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return("{0} of {1}".format(self.rank, self.suit))
def __repr__(self):
- return("{0} of {1}".format(self.rank, self.suit))
+ return("<Card {0}>".format(self))
class CardCollection:
def __init__(self, collection=[]):
self.collection = []
for i in collection:
self.collection.append(i)
def __getitem__(self, i):
return self.collection[i]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
return self.collection.index(card)
def StandardDeck():
deck = CardCollection()
for suit in SUITS.values():
for rank in RANKS.values():
deck.add(Card(rank, suit))
- return deck
+ return list(deck)
+
+
+def BeloteDeck():
+ excluded = ['Two', 'Three', 'Four', 'Five', 'Six']
+ belote_ranks = [rank for rank in RANKS.keys() if rank not in excluded]
+ deck = CardCollection()
+ for suit in SUITS.values():
+ for rank in belote_ranks:
+ deck.add(Card(RANKS[rank], suit))
+ return list(deck)
+
+
+def SixtySixDeck():
+ excluded = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
+ sixty_six_ranks = [rank for rank in RANKS.keys() if rank not in excluded]
+ deck = CardCollection()
+ for suit in SUITS.values():
+ for rank in sixty_six_ranks:
+ deck.add(Card(RANKS[rank], suit))
+ return list(deck)

Велина обнови решението на 26.03.2014 16:56 (преди над 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.__class__.__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
RANKS = {x.__name__: x for x in Rank.__subclasses__()}
SUITS = {x.__name__: x for x in Suit.__subclasses__()}
+RANK_ORDER = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three']
+SUIT_ORDER = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class Card(Rank, Suit):
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __setattr__(self, attr, value):
if hasattr(self, attr):
raise AttributeError("Attribute already has a value")
else:
self.__dict__[attr] = value
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return("{0} of {1}".format(self.rank, self.suit))
def __repr__(self):
return("<Card {0}>".format(self))
class CardCollection:
def __init__(self, collection=[]):
self.collection = []
for i in collection:
self.collection.append(i)
def __getitem__(self, i):
return self.collection[i]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
return self.collection.index(card)
def StandardDeck():
deck = CardCollection()
- for suit in SUITS.values():
- for rank in RANKS.values():
- deck.add(Card(rank, suit))
+ for suit in SUIT_ORDER:
+ for rank in RANK_ORDER:
+ deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)
def BeloteDeck():
excluded = ['Two', 'Three', 'Four', 'Five', 'Six']
- belote_ranks = [rank for rank in RANKS.keys() if rank not in excluded]
+ belote_ranks = [rank for rank in RANK_ORDER if rank not in excluded]
deck = CardCollection()
- for suit in SUITS.values():
+ for suit in SUIT_ORDER:
for rank in belote_ranks:
- deck.add(Card(RANKS[rank], suit))
+ deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)
def SixtySixDeck():
excluded = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
- sixty_six_ranks = [rank for rank in RANKS.keys() if rank not in excluded]
+ sixty_six_ranks = [rank for rank in RANK_ORDER if rank not in excluded]
deck = CardCollection()
- for suit in SUITS.values():
+ for suit in SUIT_ORDER:
for rank in sixty_six_ranks:
- deck.add(Card(RANKS[rank], suit))
+ deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)

Велина обнови решението на 26.03.2014 16:57 (преди над 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.__class__.__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
RANKS = {x.__name__: x for x in Rank.__subclasses__()}
SUITS = {x.__name__: x for x in Suit.__subclasses__()}
RANK_ORDER = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
- 'Six', 'Five', 'Four', 'Three']
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
SUIT_ORDER = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class Card(Rank, Suit):
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __setattr__(self, attr, value):
if hasattr(self, attr):
raise AttributeError("Attribute already has a value")
else:
self.__dict__[attr] = value
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return("{0} of {1}".format(self.rank, self.suit))
def __repr__(self):
return("<Card {0}>".format(self))
class CardCollection:
def __init__(self, collection=[]):
self.collection = []
for i in collection:
self.collection.append(i)
def __getitem__(self, i):
return self.collection[i]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def index(self, card):
return self.collection.index(card)
def StandardDeck():
deck = CardCollection()
for suit in SUIT_ORDER:
for rank in RANK_ORDER:
deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)
def BeloteDeck():
excluded = ['Two', 'Three', 'Four', 'Five', 'Six']
belote_ranks = [rank for rank in RANK_ORDER if rank not in excluded]
deck = CardCollection()
for suit in SUIT_ORDER:
for rank in belote_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)
def SixtySixDeck():
excluded = ['Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']
sixty_six_ranks = [rank for rank in RANK_ORDER if rank not in excluded]
deck = CardCollection()
for suit in SUIT_ORDER:
for rank in sixty_six_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return list(deck)