Solution 1

class Horse(object):
    def __init__(self, name, breed):
        self.name = name
        self.breed = breed

    def __str__(self):
        return "{name} the {breed}".format(
            name=self.name, breed=self.breed)

    def __repr__(self):
        return "Horse: {name}, {breed}".format(
            name=self.name, breed=self.breed)

Horse Representation

Horses are more than just objects. Please give them some string and machine representation using magic methods.

The Horse class should accept two attributes, name and breed.

Use the following examples to make __str__ and __repr__ magic methods to produce similar outputs.

Examples:

talking_horse = Horse("Mr. Ed", "Saddlebred")
sparkles = Horse("Charlie", "Unicorn")

team_horse_squad = [talking_horse, sparkles]

print(sparkles) # "Charlie the Unicorn"
print(talking_horse) # "Mr. Ed the Saddlebred"

print(team_horse_squad) # '[Horse: Mr. Ed, Saddlebred, Horse: Charlie, Unicorn]'

Test Cases

test horse repr - Run Test

def test_horse_repr():
    horse1 = Horse("Mr. Ed", "Saddlebred")
    horse2 = Horse("Charlie", "Unicorn")
    horse3 = Horse("Harry Trotter", "Clydesdale")

    horse_party = [horse1, horse2, horse3]

    assert str(horse_party) == '[Horse: Mr. Ed, Saddlebred, Horse: Charlie, Unicorn, Horse: Harry Trotter, Clydesdale]'

test horse str - Run Test

def test_horse_str():
    talking_horse = Horse("Mr. Ed", "Saddlebred")
    sparkles = Horse("Charlie", "Unicorn")

    assert str(sparkles) == "Charlie the Unicorn"
    assert str(talking_horse) == "Mr. Ed the Saddlebred"