Валентин обнови решението на 26.03.2014 16:45 (преди над 10 години)
+class Rank:
+ def __init__(self, symbol_):
+ if symbol_ in list(range(2,10))+['A','K','Q','J']:
+ print(symbol_)
+ self.symbol = symbol_
+ else:
+ print('None')
+
+
+class Suit:
+ def __init__(self, color_):
+ if color_ in ('red','black'):
+ self.color = color_
+
+
+class Two(Rank):
+ def __init__(self, symbol_=2):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Three(Rank):
+ def __init__(self, symbol_=3):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Four(Rank):
+ def __init__(self, symbol_=4):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Five(Rank):
+ def __init__(self, symbol_=5):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Six(Rank):
+ def __init__(self, symbol_=6):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Seven(Rank):
+ def __init__(self, symbol_=7):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+ return self.symbol
+class Eight(Rank):
+ def __init__(self, symbol_=8):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Nine(Rank):
+ def __init__(self, symbol_=9):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Ten(Rank):
+ def __init__(self, symbol_=10):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Jack(Rank):
+ def __init__(self, symbol_='J'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Queen(Rank):
+ def __init__(self, symbol_='Q'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class King(Rank):
+ def __init__(self, symbol_='K'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Ace(Rank):
+ def __init__(self, symbol_='A'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Diamonds(Suit):
+ def __init__(self, color_='red'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+class Hearts(Suit):
+ def __init__(self, color_='red'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+class Spades(Suit):
+ def __init__(self, color_='black'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+class Clubs(Suit):
+ def __init__(self, color_='black'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+
+
+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() }
+SUITS = { 'Hearts': Hearts(), \
+ 'Clubs': Clubs(), \
+ 'Spades': Spades(), \
+ 'Diamonds': Diamonds() }
+
+class Card:
+ def __init__(self, rank_, suit_):
+ self.rank = rank_
+ self.suit = suit_
+ def __getitem__(self, name):
+ return self.name
+ def __setitem__(self, name, value):
+ self.name = value