Created
June 6, 2020 09:17
-
-
Save gonzalodiaz/dfa39d15cf876ac8568e432034e2c162 to your computer and use it in GitHub Desktop.
PopulationBroken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class World: | |
"""Class to contain the properties of the World. | |
:param yearly_population: World's population by year | |
:ivar yearly_population: Internal attribute to hold the world population. | |
""" | |
def __init__(self, yearly_population: dict): | |
self.yearly_population: dict = yearly_population | |
def population(self, year: int) -> dict: | |
"""Obtain the population in the world for a given year. | |
:param year: Year of which the population wants to be known. | |
:returns: Population for that year. 0 if the year was not found. | |
""" | |
return self.yearly_population.get(year, 0) | |
def population_on_2020(self) -> int: | |
"""Obtain the population for 2020. | |
:returns: population for the year 2020. | |
""" | |
return self.population('2020') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment