EX Exercises

Task

Create a class named Animal.

Attributes

  • name: stores the name of the animal.
  • age: stores the age of the animal.

Methods

  • region(): this method should print a message describing the region or area of the world where this animal is most common (e.g., “This animal lives mostly in Africa.”).
  • sleep(): this method should print a message indicating whether the animal sleeps during the day or at night (e.g., “This animal sleeps at night.”).

Instructions

  • Define the constructor to initialize name and age.
  • Use self to access and assign the attributes.
  • Implement both methods as described above.
  • Create an object of your Animal class and test both methods.

Hint

Be creative when describing the region and sleep behavior to make your class more interesting.

Updated: