print(nemo) nemo.feed() notouchy = Blowfish("No Touchy", "spiky fish", "fish food", 77824) print(notouchy) notouchy.feed() dude = Turtle("Dude", "wise turtle", "turtle chow", 77931) print(dude) dude.feed() smooshy = Beluga("Smooshy", "darn cute whale", "whale mix", 77096) print(smooshy) smooshy.feed() tuxedo = Penguin("Tuxedo", "formal cutie", "baby fish", 77843) print(tuxedo) tuxedo.feed() def report_animals_by_attractions(*attractions): for attraction in attractions: print( f'{attraction.attraction_name} is where you can find {attraction.description} like:' ) for animal in attraction.animals: print(f'* {animal.name} the {animal.species}.') varmint_village = PettingZoo("Varmint Village",
from animals import Penguin, PaintedDog from habitats import Habitat, Aquarium Flipper = Penguin("Flipper") Flipper.swim() Flipper.run() Picasso = PaintedDog("Picasso") Picasso.run() SanDiegoAquarium = Aquarium("San Diego Aquarium") SanDiegoAquarium.add_swimmer_pythonic(Flipper) SanDiegoAquarium.add_swimmer_pythonic(Picasso) SanDiegoAquarium.add_swimmer_type_check(Picasso) print(f"The following animals live in San Diego Aquarium:") for animal in SanDiegoAquarium.animals: print(animal)
from animals import Penguin James = Penguin("James") print(James.name) James.run() James.swim()
from animals import Penguin, PaintedDog from habitats import Habitat, Aquarium # bob = Penguin("Bob") # Create a penguin bob = Penguin("Bob") bob.run() bob.swim() ralph = PaintedDog("Ralph") # Create a habitat seaworld = Aquarium("Sea World") # seaworld.add_animal(bob) # seaworld.add_animal(ralph) for animal in seaworld.animals: print(animal) seaworld.add_swimmer_pythonic(bob) seaworld.add_swimmer_pythonic(ralph) # seaworld.add_swimmer_type_check(ralph) for animal in seaworld.animals: print(f'{animal} lives in Sea World')
from animals import Penguin, PaintedDog from habitats import Habitat from habitats import Aquarium bob = Penguin("Bob") ralph = PaintedDog("Ralph") print(bob.walk()) print(bob.swim()) seaworld = Habitat("Sea World") seaworld.add_animal(bob) seaworld.add_animal(ralph) for animal in seaworld.animals: print(animal) #***** refactored after adding type checking *********# bob = Penguin("Bob") ralph = PaintedDog("Ralph") seaworld = Aquarium("Sea World") seaworld.add_swimmer_pythonic(bob) seaworld.add_swimmer_pythonic(ralph) seaworld.add_swimmer_type_check(ralph) for animal in seaworld.animals: print(f'{animal} lives in Sea World') # Ralph the Painted Dog can't swim, so please do not try to put it in the Sea World habitat
from animals import Penguin, PaintedDog from movements import IWalking from habitats import Aquarium bob = Penguin("Bob") print(bob) print(f"This is Bob: {bob}") print("Bob's legs:", bob.legs) bob.run() print("Bob's swim speed: ", bob.swim_speed) bob.swim() jim = Penguin("Jim") ralph = PaintedDog("Ralph") seaworld = Aquarium("Sea World") print(seaworld.__len__()) seaworld.add_animal(bob) seaworld.add_animal(jim) seaworld.add_animal(ralph) print(seaworld.name) for animal in seaworld.animals: print(animal)
from animals import PaintedDog from animals import Penguin from habitats import Habitat from habitats import Aquarium Bob = Penguin("Bob") # print(Bob) # Bob.run() # Bob.swim() Ralph = PaintedDog("Ralph") # print(Ralph) seaworld = Aquarium("Sea World") seaworld.add_swimmer_pythonic(Bob) seaworld.add_swimmer_pythonic(Ralph) seaworld.add_swimmer_type_check(Ralph) for animal in seaworld.animals: print(animal)
from animals import Penguin, PaintedDog from habitats import Aquarium from habitats import Habitat bob = Penguin("Bob") bob.run() bob.swim() Reggie = Penguin("Reggie") ralph = PaintedDog("Ralph") # Create a habitat seaworld = Aquarium("Sea World") seaworld.add_animal(bob) Grassmere = Habitat("Grassmere") Grassmere.add_animal(Reggie) Home = Habitat("Home") Home.add_animal(ralph) for animal in seaworld.animals: print(animal) for animal in Grassmere.animals: print(animal) for animal in Home.animals: print(animal) seaworld.add_swimmer_pythonic(bob)
from animals import Penguin, PaintedDog from habitats import Habitat, Aquarium pingu = Penguin('pingu') dog = PaintedDog('ralph') ocean = Aquarium('ocean') ocean.add_swimmer_type_check(pingu) ocean.add_swimmer_type_check(dog) for animal in ocean.animals: print(animal)
from animals import Penguin, PaintedDog, Copperhead, BettaFish, Parakeet, Earthworm from habitats import Aquarium, Aviary, Terrestrial, DirtPot waddles = Penguin("Waddles") doggy = PaintedDog("Doggy") wormy = Earthworm("Wormy") wingsy = Parakeet("Wingsy") snakey = Copperhead("Snakey") fishy = BettaFish("Fishy") wormy.digging() snakey.slithering() fishy.swim() doggy.run() waddles.run() waddles.swim() wingsy.flying() print(wingsy.__dict__) print(wormy.__dict__) seaworld = Aquarium("Sea World") seaworld.add_swimmer_type_check(waddles) seaworld.add_swimmer_type_check(fishy) seaworld.add_swimmer_type_check(snakey) skyworld = Aviary("Sky World") skyworld.add_flier_type_check(wingsy) landworld = Terrestrial("Land World") landworld.add_walking_type_check(snakey)
if __name__ == "__main__": animal_classes = [Parrot, Penguin, Dog, HouseCat, BobCat] colors = ["White", "Black", "Red", "Green", "Blue", "Striped"] habitats = ["Land", "Sea", "Air", "Tree", "Campus"] random_true_false = [True, False] zoo = [] zoo_size = 10 for _ in range(zoo_size): spec = animal_classes[random.randint(0, 4)] age = random.randint(1, 10) color = random.choice(colors) habitat = random.choice(habitats) if spec == Parrot: new_animal = Parrot(age, color, random.choice(random_true_false)) elif spec == Penguin: new_animal = Penguin(age, color) elif spec == Dog: new_animal = Dog(age, color) elif spec == HouseCat: new_animal = HouseCat(age, color) else: # BobCat try: new_animal = BobCat(age, color, habitat) except ValueError as value_error: print(habitat + " is " + str(value_error)) continue zoo.append(new_animal) print("There are {} animals in the zoo".format(len(zoo))) for animal in zoo: print('{} says {}'.format(str(animal), animal.sound()))