Skip to content

Instantly share code, notes, and snippets.

@gonzalodiaz
Created June 6, 2020 09:12
Show Gist options
  • Save gonzalodiaz/374cd1f424cd46f132929598d7224b61 to your computer and use it in GitHub Desktop.
Save gonzalodiaz/374cd1f424cd46f132929598d7224b61 to your computer and use it in GitHub Desktop.
TypingOriginal
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment