small medium large xlarge

PracProg2oop

1.

a.
```class Country:

def __init__(self, name, population, area):
""" (Country, str, int, int)

A new Country named name with population people and area area.

34482779
9984670
"""

self.name = name
self.population = population
self.area = area
```

b.

```    def is_larger(self, other):
""" (Country, Country) -> bool

Return whether this country is larger than other.

>>> usa = Country('United States of America', 313914040, 9826675)
True
False
"""

return self.area > other.area
```

c.

```    def population_density(self):
""" (Country) -> float

Return the population density of this country.

3.4535722262227995
"""

return self.population / self.area
```

d.

```    def __str__(self):
""" (Country) -> str

Return a printable representation of this country.

>>> usa = Country('United States of America', 313914040, 9826675)
>>> print(usa)
United States of America has a population of 313914040 and is 9826675 square km.
"""

return '{} has a population of {} and is {} square km.'.format(
self.name, self.population, self.area)
```

e.

``````def repr(self):
""" (Country) -> str``````
``Return a concise representation of this country.``

``````return "Country('{}', {}, {})".format(
self.name, self.population, self.area)``````
Page History
• V10: Jason Montojo [over 2 years ago]
• V9: Jason Montojo [over 2 years ago]
• V8: Paul Gries [almost 3 years ago]
• V7: Paul Gries [almost 3 years ago]
• V6: Paul Gries [almost 3 years ago]
• V5: Paul Gries [almost 3 years ago]
• V4: Paul Gries [almost 3 years ago]
• V3: Paul Gries [almost 3 years ago]
• V2: Paul Gries [almost 3 years ago]
• V1: Sourav Karwa [over 3 years ago]