Giter Club home page Giter Club logo

py-herbivores-and-carnivores's Introduction

Herbivores and carnivores

Read the guideline before starting.

Nature is well suited to reflect the principles of Object Oriented Programming. All instances of the Animal class must have health, name and hidden attribute. Health is 100 and hidden is false by default.

All alive animals should be in the class attribute Animal.alive. If the health of the animal reaches 0, the beast dies and it should be removed from Animal.alive.

lion = Carnivore("Simba")
len(Animal.alive) == 1
isinstance(Animal.alive[0], Carnivore) is True

Create a Herbivore class. This class should inherit from Animal. Herbivore has a method of hide, which changes the hidden property of the beast to the opposite value and helps to hide from carnivores.

rabbit = Herbivore("Susan")
rabbit.hide()
rabbit.hidden is True  

Create a Сarnivore class. This class should inherit from Animal. Carnivore has a bite method, which takes a herbivore object and decreases the object's health by 50. The method does not work if it is another сarnivore, or the herbivore is currently hiding.

lion = Carnivore("Lion King")
rabbit = Herbivore("Susan")
rabbit.health == 100
lion.bite(rabbit)
rabbit.health == 50  # bited

rabbit.hide()
lion.bite(rabbit)
rabbit.health == 50  # lion cannot bite hidden rabbit

rabbit.hide()
lion.bite(rabbit)
rabbit.health == 0  # rabbit is dead

rabbit in Animal.alive  # False
# there is no dead animals in Animal.alive

Also implement feature that when you print Animal.alive it should look like this:

pantera = Carnivore("Bagira")
snake = Carnivore("Kaa")
print(Animal.alive)
# [{Name: Bagira, Health: 100, Hidden: False}, {Name: Kaa, Health: 100, Hidden: False}]

Hint: Use magic method.

Note: Check your code using this checklist before pushing your solution.

py-herbivores-and-carnivores's People

Contributors

masterpieceelbow avatar abnormaltype avatar y-havryliv avatar danylott 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.