Решение на Тесте карти от Теодор Халваджиев

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

Към профила на Теодор Халваджиев

Резултати

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

Код

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
return self.__class__.__name__
class Hearts(Suit):
color = "red"
class Spades(Suit):
color = "black"
class Diamonds(Suit):
color = "red"
class Clubs(Suit):
color = "black"
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 Ace(Rank):
symbol = "A"
SUITS = {"Hearts": Hearts, "Spades": Spades,
"Diamonds": Diamonds, "Clubs": Clubs}
RANKS = {"Two": Two, "Three": Three, "Four": Four, "Five": Five,
"Six": Six, "Seven": Seven, "Eight": Eight, "Nine": Nine, "Ten": Ten,
"Jack": Jack, "Queen": Queen, "King": King, "Ace": Ace}
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, "rank", rank())
object.__setattr__(self, "suit", suit())
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 __setattr__(self, name, value):
raise AttributeError("can't set attribute")
def __delattr__(self, name):
raise AttributeError("can't delete attribute")
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop(len(self.collection) - 1)
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return self.collection.index(card)
def __getitem__(self, position):
return self.collection[position]
def __len__(self):
return len(self.collection)
def __iter__(self):
for card in self.collection:
yield card
SUITS_ORDERED = [Diamonds, Clubs, Hearts, Spades]
RANKS_ORDERED = [King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five, Four,
Three, Two, Ace]
def deck_generator(boundary):
return CardCollection([str(Card(rank, suit)) for suit in SUITS_ORDERED
for index, rank in enumerate(RANKS_ORDERED)
if index < boundary or index > 11])
def StandardDeck():
return deck_generator(13)
def BeloteDeck():
return deck_generator(7)
def SixtySixDeck():
return deck_generator(5)

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.358s

OK

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

Теодор обнови решението на 23.03.2014 22:42 (преди над 10 години)

+class Rank:
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+ def __eq__(self, other):
+ return str(self) == str(other)
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Hearts(Suit):
+ colour = "red"
+
+
+class Spades(Suit):
+ colour = "black"
+
+
+class Diamonds(Suit):
+ colour = "red"
+
+
+class Clubs(Suit):
+ colour = "black"
+
+
+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 Ace(Rank):
+ symbol = "A"
+
+SUITS = {"Hearts": Hearts, "Spades": Spades,
+ "Diamonds": Diamonds, "Clubs": Clubs}
+RANKS = {"Two": Two, "Three": Three, "Four": Four, "Five": Five,
+ "Six": Six, "Seven": Seven, "Eight": Eight, "Nine": Nine, "Ten": Ten,
+ "Jack": Jack, "Queen": Queen, "King": King, "Ace": Ace}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, "rank", rank())
+ object.__setattr__(self, "suit", suit())
+
+ 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 __setattr__(self, name, value):
+ raise AttributeError("can't set attribute")
+
+ def __delattr__(self, name):
+ raise AttributeError("can't delete attribute")
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = list(collection)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop(len(self.collection) - 1)
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[len(self.collection) - 1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ return self.collection.index(card)
+
+ def __getitem__(self, position):
+ return self.collection[position]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __iter__(self):
+ for card in self.collection:
+ yield card
+
+
+SUITS_ORDERED = [Diamonds, Clubs, Hearts, Spades]
+RANKS_ORDERED = [King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five, Four,
+ Three, Two, Ace]
+
+
+def StandardDeck():
+ standard_deck = [str(Card(rank, suit)) for suit in SUITS_ORDERED
+ for rank in RANKS_ORDERED]
+ return standard_deck
+
+
+def BeloteDeck():
+ belote_deck = [str(Card(RANKS_ORDERED[rank], suit))
+ for suit in SUITS_ORDERED for rank in range(0, 13)
+ if rank < 7 or rank > 11]
+ return belote_deck
+
+
+def SixtySixDeck():
+ sixtysix_deck = [str(Card(RANKS_ORDERED[rank], suit))
+ for suit in SUITS_ORDERED for rank in range(0, 13)
+ if rank < 5 or rank > 11]
+ return sixtysix_deck

Теодор обнови решението на 25.03.2014 19:09 (преди над 10 години)

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
return self.__class__.__name__
class Hearts(Suit):
colour = "red"
class Spades(Suit):
colour = "black"
class Diamonds(Suit):
colour = "red"
class Clubs(Suit):
colour = "black"
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 Ace(Rank):
symbol = "A"
SUITS = {"Hearts": Hearts, "Spades": Spades,
"Diamonds": Diamonds, "Clubs": Clubs}
RANKS = {"Two": Two, "Three": Three, "Four": Four, "Five": Five,
"Six": Six, "Seven": Seven, "Eight": Eight, "Nine": Nine, "Ten": Ten,
"Jack": Jack, "Queen": Queen, "King": King, "Ace": Ace}
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, "rank", rank())
object.__setattr__(self, "suit", suit())
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 __setattr__(self, name, value):
raise AttributeError("can't set attribute")
def __delattr__(self, name):
raise AttributeError("can't delete attribute")
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop(len(self.collection) - 1)
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return self.collection.index(card)
def __getitem__(self, position):
return self.collection[position]
def __len__(self):
return len(self.collection)
def __iter__(self):
for card in self.collection:
yield card
SUITS_ORDERED = [Diamonds, Clubs, Hearts, Spades]
RANKS_ORDERED = [King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five, Four,
Three, Two, Ace]
+def deck_generator(boundary):
+ return [str(Card(rank, suit)) for suit in SUITS_ORDERED
+ for index, rank in enumerate(RANKS_ORDERED)
+ if index < boundary or index > 11]
+
+
def StandardDeck():
- standard_deck = [str(Card(rank, suit)) for suit in SUITS_ORDERED
- for rank in RANKS_ORDERED]
- return standard_deck
+ return deck_generator(13)
def BeloteDeck():
- belote_deck = [str(Card(RANKS_ORDERED[rank], suit))
- for suit in SUITS_ORDERED for rank in range(0, 13)
- if rank < 7 or rank > 11]
- return belote_deck
+ return deck_generator(7)
def SixtySixDeck():
- sixtysix_deck = [str(Card(RANKS_ORDERED[rank], suit))
- for suit in SUITS_ORDERED for rank in range(0, 13)
+ return deck_generator(5)
- if rank < 5 or rank > 11]
- return sixtysix_deck

Теодор обнови решението на 26.03.2014 15:42 (преди над 10 години)

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
return self.__class__.__name__
class Hearts(Suit):
- colour = "red"
+ color = "red"
class Spades(Suit):
- colour = "black"
+ color = "black"
class Diamonds(Suit):
- colour = "red"
+ color = "red"
class Clubs(Suit):
- colour = "black"
+ color = "black"
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 Ace(Rank):
symbol = "A"
SUITS = {"Hearts": Hearts, "Spades": Spades,
"Diamonds": Diamonds, "Clubs": Clubs}
RANKS = {"Two": Two, "Three": Three, "Four": Four, "Five": Five,
"Six": Six, "Seven": Seven, "Eight": Eight, "Nine": Nine, "Ten": Ten,
"Jack": Jack, "Queen": Queen, "King": King, "Ace": Ace}
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, "rank", rank())
object.__setattr__(self, "suit", suit())
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 __setattr__(self, name, value):
raise AttributeError("can't set attribute")
def __delattr__(self, name):
raise AttributeError("can't delete attribute")
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop(len(self.collection) - 1)
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return self.collection.index(card)
def __getitem__(self, position):
return self.collection[position]
def __len__(self):
return len(self.collection)
def __iter__(self):
for card in self.collection:
yield card
SUITS_ORDERED = [Diamonds, Clubs, Hearts, Spades]
RANKS_ORDERED = [King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five, Four,
Three, Two, Ace]
def deck_generator(boundary):
- return [str(Card(rank, suit)) for suit in SUITS_ORDERED
+ return CardCollection([str(Card(rank, suit)) for suit in SUITS_ORDERED
for index, rank in enumerate(RANKS_ORDERED)
- if index < boundary or index > 11]
+ if index < boundary or index > 11])
def StandardDeck():
return deck_generator(13)
def BeloteDeck():
return deck_generator(7)
def SixtySixDeck():
return deck_generator(5)

Теодор обнови решението на 26.03.2014 15:43 (преди над 10 години)

class Rank:
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __eq__(self, other):
return str(self) == str(other)
def __str__(self):
return self.__class__.__name__
class Hearts(Suit):
color = "red"
class Spades(Suit):
color = "black"
class Diamonds(Suit):
color = "red"
class Clubs(Suit):
color = "black"
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 Ace(Rank):
symbol = "A"
SUITS = {"Hearts": Hearts, "Spades": Spades,
"Diamonds": Diamonds, "Clubs": Clubs}
RANKS = {"Two": Two, "Three": Three, "Four": Four, "Five": Five,
"Six": Six, "Seven": Seven, "Eight": Eight, "Nine": Nine, "Ten": Ten,
"Jack": Jack, "Queen": Queen, "King": King, "Ace": Ace}
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, "rank", rank())
object.__setattr__(self, "suit", suit())
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 __setattr__(self, name, value):
raise AttributeError("can't set attribute")
def __delattr__(self, name):
raise AttributeError("can't delete attribute")
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop(len(self.collection) - 1)
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return self.collection.index(card)
def __getitem__(self, position):
return self.collection[position]
def __len__(self):
return len(self.collection)
def __iter__(self):
for card in self.collection:
yield card
SUITS_ORDERED = [Diamonds, Clubs, Hearts, Spades]
RANKS_ORDERED = [King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five, Four,
Three, Two, Ace]
def deck_generator(boundary):
return CardCollection([str(Card(rank, suit)) for suit in SUITS_ORDERED
- for index, rank in enumerate(RANKS_ORDERED)
- if index < boundary or index > 11])
+ for index, rank in enumerate(RANKS_ORDERED)
+ if index < boundary or index > 11])
def StandardDeck():
return deck_generator(13)
def BeloteDeck():
return deck_generator(7)
def SixtySixDeck():
return deck_generator(5)