예제 #1
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.")
예제 #2
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.")
예제 #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
파일: 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)
예제 #6
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: