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)
Esempio n. 2
0
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

James = Penguin("James")
print(James.name)

James.run()
James.swim()
Esempio n. 5
0
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)