September 2013
Intermediate to advanced
350 pages
9h 38m
English
Here are some exercises for you to try on your own. Solutions are available at http://pragprog.com/titles/gwpy2/practical-programming.
In this exercise, you will implement class Country, which represents a country with a name, a population, and an area.
Here is a sample interaction from the Python shell:
| | >>> canada = Country('Canada', 34482779, 9984670) |
| | >>> canada.name |
| | 'Canada' |
| | >>> canada.population |
| | 34482779 |
| | >>> canada.area |
| | 9984670 |
The code above cannot be executed yet because class Country does not exist. Define Country with a constructor (method __init__) that has four parameters: a country, its name, its population, and its area.
Consider this code:
| | >>> canada |
Read now
Unlock full access