Exemplo n.º 1
0
def main():

    try:

        # Hamster
        A = pets.Pet("Hamster")
        print(A)

        # Dog named Fido who chases Cats
        B = pets.Dog("Fido")
        print(B)

        # Cat named Fluffy who hates everything
        C = pets.Cat("Fluffy", "everything")
        print(C)

        D = pets.Pet("Ferret", "Aang")
        print(D)

        E = pets.Cat("Pepper", "plastic bags")
        print(E)

        G = pets.Dog("Woof", "other dogs")
        print(G)

        F = pets.Pet("parrot", "brazil")
        print(F)

    except pets.PetError:

        print("Got a pet error.")
Exemplo n.º 2
0
    def testinstances(self):
        randompet = pets.Pet("Brutus", 5)
        mydog = pets.Dog("Brutus", 2)
        mycat = pets.Cat("Floyd", 10)

        self.assertIsInstance(mydog, pets.Pet)
        self.assertIsInstance(mydog, pets.Dog)
        self.assertFalse(isinstance(mydog, pets.Cat))


# python -m unittest standardpythonunittests
Exemplo n.º 3
0
def main():

    try:

        A = pets.Pet("hamster")
        print(A)

        # Dog named Fido who chases Cats
        B = pets.Dog("Fido")
        print(B)

        # Cat named Fluffy who hates everything
        C = pets.Cat("Fluffy", "everything")
        print(C)

        D = pets.Pet("pig")
        print(D)

    except pets.PetError:

        print("Got a pet error.")
Exemplo n.º 4
0
def main():

    try:

        # Hamster
        A = pets.Pet("Hamster")
        print(A)

        #Dog named Fido who chases Cats
        B = pets.Dog("Fido", "Mail Men")
        print(B)

        # Cat named Fluffy who hates everything
        C = pets.Cat("Fluffy", "everything")
        print(C)

        D = pets.Pet("Lizard", "Spike")
        print(D)

    except pets.PetError:

        print("Got a pet error.")
Exemplo n.º 5
0
def main():

    try:

        # Hamster
        A = pets.Pet("Hamster")
        print("A is a ", A)
        A = pets.Cat("Dora the Explorer", "mice")
        print("A reinitialized and is now ", str(A))
        print(A)
        # Dog named Fido who chases Cats
        B = pets.Dog("Fido")
        print(B)

        # Cat named Fluffy who hates everything
        C = pets.Cat("Fluffy", "everything")
        print(str(C))
        print(C)
        B = pets.Pet("penguin")

    except pets.PetError:

        print("Got a pet error.")
Exemplo n.º 6
0
def main():

    pets.Pet.species_set = {
        'dog', 'cat', 'horse', 'gerbil', 'hamster', 'ferret'
    }

    try:

        # Hamster
        A = pets.Pet("Hamster")
        print(A)

        # Dog named Fido who chases Cats
        B = pets.Dog("Fido")
        print(B)

        # Cat named Fluffy who hates everything
        C = pets.Cat("Fluffy", "everything")
        print(C)

    except pets.PetError:

        print("Got a pet error.")
Exemplo n.º 7
0
      "                        _-~~             ~~-_\n"
      "                      _-~                    /~-_\n"
      "   /^\__/^\         /~  \                   /    \ \n"
      " /|  O|| O|        /      \_______________/        \ \n"
      "| |___||__|      /       /                \          \ \n"
      "|          \    /      /                    \          \ \n"
      "|   (_______) /______/                        \_________ \ \n"
      "|         / /         \                      /            \ \n"
      " \         \^\\         \                  /               \     /\n"
      "   \         ||           \______________/      _-_       //\__//\n"
      "     \       ||------_-~~-_ ------------- \ --/~   ~\    || __/\n"
      "       ~-----||====/~     |==================|       |/~~~~~\n"
      "        (_(__/  ./     /                    \_\      \.\n"
      "             (_(___/                         \_____)_)\n")

turtle = pets.Pet(input("What do you want to name your turtle? "),
                  random.randint(1, 2))
name = turtle.get_name()
print("Your turtle's name is now", name + ".")
print()


def print_attributes():
    print("Attributes")
    print("-----------")
    print("Hunger:\t\t ",
          "+ " + format("-" * turtle.get_hunger(), "10s") + " +")
    print("Cleanliness: ",
          "+ " + format("-" * turtle.get_cleanliness(), "10s") + " +")
    print("Affinity:\t ",
          "+ " + format("-" * turtle.get_affinity(), "10s") + " +")
    print("Loyalty:\t ",
Exemplo n.º 8
0
##
## Demonstrate some of the operations of the Pet classes
##

import pets

try:

    # Hamster
    A = pets.Pet("Hamster")
    print(A)
    # Dog named Fido who chases Cats
    B = pets.Dog("Fido")
    print(B)
    # Cat named Fluffy who hates everything
    C = pets.Cat("Fluffy", "everything")
    print(C)
    #horse
    D = pets.Pet("Horse", "Bill")
    print(D)
    #dog named Spot who chases birds
    E = pets.Dog("Spot", "birds")
    print(E)
    #stray cat
    G = pets.Cat()
    print(G)
    #fish -- error
    F = pets.Pet("Fish", "barry")
    print(F)

except pets.PetError: