Решение на Тесте карти от Денис Бялев

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

Към профила на Денис Бялев

Резултати

  • 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 type(self).__name__
class Suit:
def __init__(self, color):
self.color=color
def __eq__(self, other):
return self.color == other.color and str(self) == str(other)
def __str__(self):
return type(self).__name__
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
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 Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
rank_classes=[Ace(), Two(), Three(), Four(), Five(), Six(), Seven(),
Eight(), Nine(), Ten(), Jack(), Queen(), King()]
suit_classes=[Hearts(), Spades(), Diamonds(), Clubs()]
RANKS={type(x).__name__:type(x) for x in rank_classes}
SUITS={type(x).__name__:type(x) for x in suit_classes}
class Card:
_rank=[]
_suit=[]
def __init__(self, rank, suit):
self._rank=rank()
self._suit=suit()
def __eq__(self, other):
return self._rank == other._rank and self._suit == other._suit
def __str__(self):
return str(self._rank) + " of " + str(self._suit)
def __repr__(self):
return "Card " + str(self)
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
@rank.setter
def rank(self, value):
raise TypeError
@suit.setter
def suit(self, value):
raise TypeError
class CardCollection:
def __init__(self, colection=[]):
self.index_number=0
self.colection=[]
for x in colection:
self.colection.append(x)
self.index_number += 1
def add(self, card):
self.colection.append(card)
self.index_number += 1
def __iter__(self):
return self
def __next__(self):
if self.index_number == 0:
raise StopIteration
self.index_number=len(self.colection)
self.index_number -= 1
return self.colection[self.index_number]
def __getitem__(self, i):
if i > len(self.colection):
raise ValueError
else:
return (self.colection)[i]
def draw(self, index_number):
self.index_number -= 1
return (self.colection).pop(index_number)
def draw_from_top(self):
self.index_number -= 1
return (self.colection).pop()
def draw_from_bottom(self):
self.index_number -= 1
return (self.colection).pop(0)
def top_card(self):
return (self.colection)[len(self) - 1]
def bottom_card(self):
return (self.colection)[0]
def index(self, card):
return (self.colection).index(card)
def __len__(self):
return len(self.colection)
def __eq__(self, other):
return self.colection == other.colection
standart_ranks=["Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King"]
suits_for_deck=["Spades", "Hearts", "Clubs", "Diamonds"]
belot_ranks=["Ace", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King"]
sixty_six_ranks=["Ace", "Nine", "Ten", "Jack", "Queen", "King"]
def StandardDeck():
deck=CardCollection()
for suit in suits_for_deck:
for rank in standart_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck=CardCollection()
for suit in suits_for_deck:
for rank in belot_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck=CardCollection()
for suit in suits_for_deck:
for rank in sixty_six_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return deck

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.023s

OK

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

Денис обнови решението на 25.03.2014 18:42 (преди над 10 години)

+class Rank:
+ symbol=[]
+ def __init__(self, symbol):
+ self.symbol=symbol
+
+ def __eq__(self, other):
+ return self.symbol==other.symbol
+
+ def __str__(self):
+ return type(self).__name__
+
+class Suit:
+ def __init__(self, color):
+ self.color=color
+
+ def __eq__(self, other):
+ return self.color==other.color
+
+ def __str__(self):
+ return type(self).__name__
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self,'A')
+
+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 Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Clubs')
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Hearts')
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Diamonds')
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self,'Spades')
+
+t=[Ace(), Two(), Three(), Four(), Five(), Six(), Seven(), Eight(), Nine(),
+ Ten(), Jack(), Queen(), King()]
+
+s=[Hearts(), Spades(), Diamonds(), Clubs()]
+
+RANKS={type(x).__name__:type(x) for x in t}
+SUITS={x.color:type(x) for x in s}
+
+class Card:
+ rank, suit= [], []
+
+ def __init__(self, rank, suit):
+ self.rank=rank()
+ self.suit=suit()
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return str(self.rank) + " of " + str(self.suit)
+
+ def __repr__(self):
+ return "Card " + str(self)
+
+class CardCollection:
+
+ def __init__(self, colection=[]):
+ self.index=0
+ self.colection=[]
+ for x in colection:
+ self.colection.append(x)
+ self.index+=1
+
+ def add(self, card):
+ self.colection.append(card)
+ self.index += 1
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ if self.index == 0:
+ raise StopIteration
+ self.index=len(self.colection)
+ self.index -= 1
+ return self.colection[self.index]
+
+ def __getitem__(self, i):
+ return (self.colection)[i]
+
+ def draw(self, index):
+ self.index -= 1
+ return (self.colection).pop(index)
+
+ def draw_from_top(self):
+ self.index -= 1
+ return (self.colection).pop()
+
+ def draw_from_bottom(self):
+ self.index -= 1
+ return (self.colection).pop(0)
+
+ def top_card(self):
+ return (self.colection)[len(self)-1]
+
+ def bottom_card(self):
+ return (self.colection)[0]
+
+ def index(self, card):
+ return (self.colection).index(card)
+
+ def __len__(self):
+ return len(self.colection)
+
+ def __eq__(self, other):
+ return self.colection == other.colection
+
+
+standart_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three", "Two", "Ace"]
+suits_for_deck=["Diamonds", "Clubs", "Hearts", "Spades"]
+belot_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Ace"]
+sixty_six_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Ace"]
+
+def StandartDeck():
+ deck=CardCollection()
+ for x in suits_for_deck:
+ for y in standart_ranks:
+ deck.add(Card(RANKS[y], SUITS[x]))
+ return deck
+
+def BeloteDeck():
+ deck=CardCollection()
+ deck.draw_from_bottom()
+ for x in suits_for_deck:
+ for y in belot_ranks:
+ deck.add(Card(RANKS[y], SUITS[x]))
+ return deck
+
+def SixtySixDeck():
+ deck=CardCollection()
+ deck.draw_from_bottom()
+ for x in suits_for_deck:
+ for y in sixty_six_ranks:
+ deck.add(Card(RANKS[y], SUITS[x]))
+ return deck

Денис обнови решението на 26.03.2014 13:36 (преди над 10 години)

class Rank:
symbol=[]
def __init__(self, symbol):
self.symbol=symbol
def __eq__(self, other):
- return self.symbol==other.symbol
+ return self.symbol == other.symbol
def __str__(self):
return type(self).__name__
class Suit:
def __init__(self, color):
self.color=color
def __eq__(self, other):
- return self.color==other.color
+ return self.color == other.color and str(self) == str(other)
def __str__(self):
return type(self).__name__
class Ace(Rank):
def __init__(self):
- Rank.__init__(self,'A')
+ Rank.__init__(self, 'A')
class Two(Rank):
def __init__(self):
- Rank.__init__(self,'2')
+ Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
- Rank.__init__(self,'3')
+ Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
- Rank.__init__(self,'4')
+ Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
- Rank.__init__(self,'5')
+ Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
- Rank.__init__(self,'6')
+ Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
- Rank.__init__(self,'7')
+ Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
- Rank.__init__(self,'8')
+ Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
- Rank.__init__(self,'9')
+ Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
- Rank.__init__(self,'10')
+ Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
- Rank.__init__(self,'J')
+ Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
- Rank.__init__(self,'Q')
+ Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
- Rank.__init__(self,'K')
+ Rank.__init__(self, 'K')
class Clubs(Suit):
def __init__(self):
- Suit.__init__(self,'Clubs')
+ Suit.__init__(self, 'black')
class Hearts(Suit):
def __init__(self):
- Suit.__init__(self,'Hearts')
+ Suit.__init__(self, 'red')
class Diamonds(Suit):
def __init__(self):
- Suit.__init__(self,'Diamonds')
+ Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
- Suit.__init__(self,'Spades')
+ Suit.__init__(self, 'black')
-t=[Ace(), Two(), Three(), Four(), Five(), Six(), Seven(), Eight(), Nine(),
- Ten(), Jack(), Queen(), King()]
+rank_classes=[Ace(), Two(), Three(), Four(), Five(), Six(), Seven(),
+ Eight(), Nine(), Ten(), Jack(), Queen(), King()]
-s=[Hearts(), Spades(), Diamonds(), Clubs()]
+suit_classes=[Hearts(), Spades(), Diamonds(), Clubs()]
-RANKS={type(x).__name__:type(x) for x in t}
-SUITS={x.color:type(x) for x in s}
+RANKS={type(x).__name__:type(x) for x in rank_classes}
+SUITS={type(x).__name__:type(x) for x in suit_classes}
class Card:
- rank, suit= [], []
-
def __init__(self, rank, suit):
- self.rank=rank()
- self.suit=suit()
+ self._rank=rank()
+ self._suit=suit()
def __eq__(self, other):
- return self.rank == other.rank and self.suit == other.suit
+ return self._rank == other._rank and self._suit == other._suit
def __str__(self):
- return str(self.rank) + " of " + str(self.suit)
+ return str(self._rank) + " of " + str(self._suit)
def __repr__(self):
return "Card " + str(self)
+
+ @property
+ def rank(self):
+ return repr(self._rank)
+ @property
+ def suit(self):
+ return repr(self._suit)
+
class CardCollection:
def __init__(self, colection=[]):
- self.index=0
+ self.index_number=0
self.colection=[]
for x in colection:
self.colection.append(x)
- self.index+=1
+ self.index_number += 1
def add(self, card):
self.colection.append(card)
- self.index += 1
+ self.index_number += 1
def __iter__(self):
return self
def __next__(self):
- if self.index == 0:
+ if self.index_number == 0:
raise StopIteration
- self.index=len(self.colection)
- self.index -= 1
- return self.colection[self.index]
+ self.index_number=len(self.colection)
+ self.index_number -= 1
+ return self.colection[self.index_number]
def __getitem__(self, i):
- return (self.colection)[i]
+ if i > len(self.colection):
+ raise ValueError
+ else:
+ return (self.colection)[i]
- def draw(self, index):
- self.index -= 1
- return (self.colection).pop(index)
+ def draw(self, index_number):
+ self.index_number -= 1
+ return (self.colection).pop(index_number)
def draw_from_top(self):
- self.index -= 1
+ self.index_number -= 1
return (self.colection).pop()
def draw_from_bottom(self):
- self.index -= 1
+ self.index_number -= 1
return (self.colection).pop(0)
def top_card(self):
- return (self.colection)[len(self)-1]
+ return (self.colection)[len(self) - 1]
def bottom_card(self):
return (self.colection)[0]
def index(self, card):
return (self.colection).index(card)
def __len__(self):
return len(self.colection)
def __eq__(self, other):
return self.colection == other.colection
-standart_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three", "Two", "Ace"]
-suits_for_deck=["Diamonds", "Clubs", "Hearts", "Spades"]
-belot_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Ace"]
-sixty_six_ranks=["King", "Queen", "Jack", "Ten", "Nine", "Ace"]
+standart_ranks=["Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
+ "Eight", "Nine", "Ten", "Jack", "Queen", "King"]
+suits_for_deck=["Spades", "Hearts", "Clubs", "Diamonds"]
+belot_ranks=["Ace", "Seven", "Eight", "Nine", "Ten",
+ "Jack", "Queen", "King"]
+sixty_six_ranks=["Ace", "Nine", "Ten", "Jack", "Queen", "King"]
-def StandartDeck():
+def StandardDeck():
deck=CardCollection()
- for x in suits_for_deck:
- for y in standart_ranks:
- deck.add(Card(RANKS[y], SUITS[x]))
+ for suit in suits_for_deck:
+ for rank in standart_ranks:
+ deck.add(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck=CardCollection()
- deck.draw_from_bottom()
- for x in suits_for_deck:
- for y in belot_ranks:
- deck.add(Card(RANKS[y], SUITS[x]))
+ for suit in suits_for_deck:
+ for rank in belot_ranks:
+ deck.add(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck=CardCollection()
- deck.draw_from_bottom()
- for x in suits_for_deck:
- for y in sixty_six_ranks:
- deck.add(Card(RANKS[y], SUITS[x]))
+ for suit in suits_for_deck:
+ for rank in sixty_six_ranks:
+ deck.add(Card(RANKS[rank], SUITS[suit]))
return deck

Денис обнови решението на 26.03.2014 14:04 (преди над 10 години)

class Rank:
- symbol=[]
def __init__(self, symbol):
self.symbol=symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return type(self).__name__
class Suit:
def __init__(self, color):
self.color=color
def __eq__(self, other):
return self.color == other.color and str(self) == str(other)
def __str__(self):
return type(self).__name__
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
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 Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
rank_classes=[Ace(), Two(), Three(), Four(), Five(), Six(), Seven(),
Eight(), Nine(), Ten(), Jack(), Queen(), King()]
suit_classes=[Hearts(), Spades(), Diamonds(), Clubs()]
RANKS={type(x).__name__:type(x) for x in rank_classes}
SUITS={type(x).__name__:type(x) for x in suit_classes}
class Card:
+ _rank=[]
+ _suit=[]
def __init__(self, rank, suit):
self._rank=rank()
self._suit=suit()
def __eq__(self, other):
return self._rank == other._rank and self._suit == other._suit
def __str__(self):
return str(self._rank) + " of " + str(self._suit)
def __repr__(self):
return "Card " + str(self)
@property
def rank(self):
- return repr(self._rank)
+ return self._rank
@property
def suit(self):
- return repr(self._suit)
+ return self._suit
+ @rank.setter
+ def rank(self, value):
+ raise TypeError
+
+ @suit.setter
+ def suit(self, value):
+ raise TypeError
+
+
class CardCollection:
def __init__(self, colection=[]):
self.index_number=0
self.colection=[]
for x in colection:
self.colection.append(x)
self.index_number += 1
def add(self, card):
self.colection.append(card)
self.index_number += 1
def __iter__(self):
return self
def __next__(self):
if self.index_number == 0:
raise StopIteration
self.index_number=len(self.colection)
self.index_number -= 1
return self.colection[self.index_number]
def __getitem__(self, i):
if i > len(self.colection):
raise ValueError
else:
return (self.colection)[i]
def draw(self, index_number):
self.index_number -= 1
return (self.colection).pop(index_number)
def draw_from_top(self):
self.index_number -= 1
return (self.colection).pop()
def draw_from_bottom(self):
self.index_number -= 1
return (self.colection).pop(0)
def top_card(self):
return (self.colection)[len(self) - 1]
def bottom_card(self):
return (self.colection)[0]
def index(self, card):
return (self.colection).index(card)
def __len__(self):
return len(self.colection)
def __eq__(self, other):
return self.colection == other.colection
standart_ranks=["Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King"]
suits_for_deck=["Spades", "Hearts", "Clubs", "Diamonds"]
belot_ranks=["Ace", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King"]
sixty_six_ranks=["Ace", "Nine", "Ten", "Jack", "Queen", "King"]
def StandardDeck():
deck=CardCollection()
for suit in suits_for_deck:
for rank in standart_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return deck
def BeloteDeck():
deck=CardCollection()
for suit in suits_for_deck:
for rank in belot_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
return deck
def SixtySixDeck():
deck=CardCollection()
for suit in suits_for_deck:
for rank in sixty_six_ranks:
deck.add(Card(RANKS[rank], SUITS[suit]))
- return deck
+ return deck