예제 #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.")
예제 #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
예제 #3
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.")
예제 #4
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)

    except pets.PetError:

        print("Got a pet error.")
예제 #5
0
파일: lab13.py 프로젝트: Pshypher/tpocup
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.")
# python classinheritancetrials.py

import sys
sys.path.append('./classes')

import pets


def MakeThePetSoundOff(thepet):
    if (isinstance(thepet, pets.Pet)):
        print(thepet.SaySomething())
    else:
        print("Class is not an instance of pets.Pet")


mydog = pets.Dog("Brutus", 2)
mycat = pets.Cat("Floyd", 10)

MakeThePetSoundOff(mydog)
MakeThePetSoundOff(mycat)
예제 #7
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: