

class Player:

    def __init__(self, name, rank):
        self.name = name
        self.rank = rank

    def __repr__(self):
        return '<{:s}(name={:s}, rank={:d})>'.format(self.__class__.__name__, self.name, self.rank)


    def __str__(self):
        rank_str = ''
        if self.rank < 0:
            rank_str = '{:d}K'.format(-self.rank)
        else:
            rank_str = '{:d}D'.format(self.rank)

        return '{:s} {:s}'.format(self.name, rank_str)


class Ladder:

    def __init__(self, standings):
        self.standings = standings

    def __str__(self):
        the_string = 'Ladder standings:'
        position = 1
        for player in self.standings:
            the_string += '\n    {:d}. {:s}'.format(position, str(player))
            position += 1
        return the_string


if __name__ == '__main__':
    ladder = Ladder([Player('Andrew', -1), Player('Walther', 5), Player('Milan', -6)])
    print(ladder)



class Player:

    def __init__(self, name, rank):
        self.name = name
        self.rank = rank

    def __repr__(self):
        return '<{:s}(name={:s}, rank={:d})>'.format(self.__class__.__name__, self.name, self.rank)

    def __str__(self):
        rank_str = ''
        if self.rank < 0:
            rank_str = '{:d}K'.format(-self.rank)
        else:
            rank_str = '{:d}D'.format(self.rank)
        return '{:s} {:s}'.format(self.name, rank_str)


class Ladder:

    def __init__(self, standings):
        self.standings = standings

    def __str__(self):
        the_string = 'Ladder standings:'
        position = 1
        for player in self.standings:
            the_string += '\n    {:d}. {:s}'.format(position, str(player))
            position += 1
        return the_string

    def players(self):
        return set(self.standings)

    def match_valid(self, player_one, player_two):
        if not {player_one, player_two} < self.players():
            return False
        return True

if __name__ == '__main__':
    ladder = Ladder([Player('Andrew', -1), Player('Walther', 5), Player('Milan', -6)])
    print(ladder)

Add players, match_valid to Ladder
Add players, match_valid to Ladder

-Add rudimentary players() method that creates a set
-Add match_valid() method that *only* checks that players are in
 the ladder standings

  
  
  class Player:
  
      def __init__(self, name, rank):
          self.name = name
          self.rank = rank
  
      def __repr__(self):
          return '<{:s}(name={:s}, rank={:d})>'.format(self.__class__.__name__, self.name, self.rank)
  
- 
      def __str__(self):
          rank_str = ''
          if self.rank < 0:
              rank_str = '{:d}K'.format(-self.rank)
          else:
              rank_str = '{:d}D'.format(self.rank)
- 
          return '{:s} {:s}'.format(self.name, rank_str)
  
  
  class Ladder:
  
      def __init__(self, standings):
          self.standings = standings
  
      def __str__(self):
          the_string = 'Ladder standings:'
          position = 1
          for player in self.standings:
              the_string += '\n    {:d}. {:s}'.format(position, str(player))
              position += 1
          return the_string
  
+     def players(self):
+         return set(self.standings)
+ 
+     def match_valid(self, player_one, player_two):
+         if not {player_one, player_two} < self.players():
+             return False
+         return True
  
  if __name__ == '__main__':
      ladder = Ladder([Player('Andrew', -1), Player('Walther', 5), Player('Milan', -6)])
      print(ladder)
  
Add players, match_valid to Ladder
## Code Before:


class Player:

    def __init__(self, name, rank):
        self.name = name
        self.rank = rank

    def __repr__(self):
        return '<{:s}(name={:s}, rank={:d})>'.format(self.__class__.__name__, self.name, self.rank)


    def __str__(self):
        rank_str = ''
        if self.rank < 0:
            rank_str = '{:d}K'.format(-self.rank)
        else:
            rank_str = '{:d}D'.format(self.rank)

        return '{:s} {:s}'.format(self.name, rank_str)


class Ladder:

    def __init__(self, standings):
        self.standings = standings

    def __str__(self):
        the_string = 'Ladder standings:'
        position = 1
        for player in self.standings:
            the_string += '\n    {:d}. {:s}'.format(position, str(player))
            position += 1
        return the_string


if __name__ == '__main__':
    ladder = Ladder([Player('Andrew', -1), Player('Walther', 5), Player('Milan', -6)])
    print(ladder)

## Instruction:
Add players, match_valid to Ladder
## Code After:


class Player:

    def __init__(self, name, rank):
        self.name = name
        self.rank = rank

    def __repr__(self):
        return '<{:s}(name={:s}, rank={:d})>'.format(self.__class__.__name__, self.name, self.rank)

    def __str__(self):
        rank_str = ''
        if self.rank < 0:
            rank_str = '{:d}K'.format(-self.rank)
        else:
            rank_str = '{:d}D'.format(self.rank)
        return '{:s} {:s}'.format(self.name, rank_str)


class Ladder:

    def __init__(self, standings):
        self.standings = standings

    def __str__(self):
        the_string = 'Ladder standings:'
        position = 1
        for player in self.standings:
            the_string += '\n    {:d}. {:s}'.format(position, str(player))
            position += 1
        return the_string

    def players(self):
        return set(self.standings)

    def match_valid(self, player_one, player_two):
        if not {player_one, player_two} < self.players():
            return False
        return True

if __name__ == '__main__':
    ladder = Ladder([Player('Andrew', -1), Player('Walther', 5), Player('Milan', -6)])
    print(ladder)
