Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. class Country: # creates the Country class
  2. def __init__(self, name, pop, area, continent): # constructor that initializes name, pop, area, continent
  3. self._pop = pop
  4. self._area = area
  5. self._continent = continent
  6. self._name = name
  7.  
  8. def __repr__(self): # constructor that returns class methods as a string
  9. return "%s (pop: %s, size: %s) in %s" % (str(self._name), str(self._pop), str(self._area), str(self._continent))
  10.  
  11. # population of a country
  12. def setPopulation(self, pop): # set the population
  13. self._pop = self._pop + pop
  14.  
  15. def getPopulation(self): # call the population
  16. return self._pop
  17.  
  18. # area of a country
  19. def setArea(self, area): # set the area
  20. self._area = self._area + area
  21.  
  22. def getArea(self): # call the area
  23. return self._area
  24.  
  25. # continent of a country
  26. def setContinent(self, continent): # set the continent
  27. self._continent = self._continent + continent
  28.  
  29. def getContinent(self): # call the continent
  30. return self._continent
  31.  
  32. # name of a country
  33. def setName(self, name): # set the name
  34. self._name = self._name + name
  35.  
  36. def getName(self): # call the name
  37. return self._name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement