Advertisement
UniQuet0p1

Untitled

Nov 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. """A small exercise in zookeeping."""
  2. import math
  3. from functools import reduce
  4.  
  5.  
  6. class Animal:
  7. """Animal."""
  8.  
  9. def __init__(self, species: str, scientific_name: str, age_up_to: int, weight_range: tuple, height_range: tuple,
  10. diet: str, habitat: str):
  11. """Initialize the Animal object."""
  12. self.species = species
  13. self.scientific_name = scientific_name
  14. self.age_up_to = age_up_to
  15. self.weight_range = weight_range
  16. self.height_range = height_range
  17. self.diet = diet
  18. self.habitat = habitat
  19.  
  20. def __repr__(self):
  21. """Animal object representation."""
  22. return self.species
  23.  
  24.  
  25. def find_smallest_animal_by_weight(animal_list: list) -> Animal:
  26. """
  27. Find the smallest animal by weight.
  28.  
  29. As we want to know the smallest possible option, take the starting value of the weight range as a basis.
  30. If multiple animals are of the same weight, return the first one in the list.
  31.  
  32. :param animal_list: input list of animals
  33. :return: Animal object
  34. """
  35. return animal_list.min(self.weight_range).First
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement