GithubHelp home page GithubHelp logo

py-feed-animals's Introduction

Feed animals

  • Read the guideline before start All animals love delicious food. Let's create a new class to feed them. Create class Animal which constructor takes three arguments:
  • name - the animal name
  • appetite - an integer that shows how much food points this animal need to eat to be full.
  • is_hungry - boolean that shows if animal is ready to eat with True default value.

Animal should have two methods:

  • print_name - should print name in the following format: Hello, my name is {name}
  • feed - should print Eating {appetite} food points..., set is_hungry to False and return number of eaten food points if animal is hungry. Otherwise, it should return 0.

Example:

lion = Animal("Lion", 25)
lion.print_name()  # "Hello, I'm Lion"
food_points = lion.feed()  # "Eating 25 food points..."
print(food_points)  # 25
print(lion.is_hungry)  # False
print(lion.feed())  # 0

There is a well-known fact that all cats eat 3 food points at a time. Also, they can catch a mouse. Write Cat class which is a child of Animal. It should have a constructor with two arguments:

  • name - the name of a cat
  • is_hungry - with True default value

Note: you need call the super class constructor with appetite equal to 3.

Cat should have only one additional method catch_mouse which should print The hunt began!

Example:

cat = Cat("Cat")
cat.print_name()  # "Hello, I'm Cat"
cat.feed()  # "Eating 3 food points"

cat2 = Cat("Cat", False)
print(cat2.feed())  # 0
cat2.catch_mouse()  # "The hunt began!"

The last class you should implement is a Dog class. Its constructor should have two arguments:

  • name - the name of a dog
  • is_hungry - with True default value

All dogs should have appetite equal to 7.

Dog should have one additional method bring_slippers that should print The slippers delivered!

Example:

dog = Dog("Dog")
dog.print_name()  # "Hello, I'm Dog"
dog.feed()  # "Eating 7 food points"

dog2 = Dog("Dog", False)
print(dog2.feed())  # 0
dog2.bring_slippers()  # "The slippers delivered!"

Now, it's time to feed many animals at a time. Implement feed_animals function which takes a list of animals and should return a sum of food points that is needed to feed all hungry animals from this list.

Example:

cat = Cat("Cat", False)
lion = Animal("Lion", 25, True)
dog = Dog("Dog")
feed_animals([cat, lion, dog]) == 28

py-feed-animals's People

Contributors

ivanramyk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.