Skip to content

Instantly share code, notes, and snippets.

@diogoaurelio
Created June 21, 2017 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogoaurelio/c37a86003ca38b5f25f5890dcddf28f7 to your computer and use it in GitHub Desktop.
Save diogoaurelio/c37a86003ca38b5f25f5890dcddf28f7 to your computer and use it in GitHub Desktop.
class Country:
"""
Convenience class for storing
data relative to a given country
"""
def __init__(self, country_name, population, continent):
"""
Default constructor
:param country_name: str
:param population: float
:param continent: str
"""
if not isinstance(country_name, str):
raise ValueError("country_name param must be a string")
if not isinstance(population, float):
raise ValueError("population param must be a float")
if not isinstance(continent, str):
raise ValueError("continent param must be a string")
self.country_name = country_name
self.population = population
self.continent = continent
def get_population_in_millions(self):
return round(self.population, 2)
def test_population():
"""
Note: If the result is wrong, calling test_population
will throw exception 'AssertionError'
"""
country = Country("myFakeCountry", 10.0, "EU")
expected = 10.00
result = expected == country.get_population_in_millions()
print("Test result = {res}".format(res=result))
assert result
test_population()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment