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.")
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.")
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.")
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)
## ## 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: