|
5 | 5 | we recommend using rich since that is built into cmd2.
|
6 | 6 |
|
7 | 7 | Data comes from World Population Review: https://worldpopulationreview.com/
|
| 8 | +and https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal) |
8 | 9 | """
|
9 | 10 |
|
10 | 11 | from rich.table import Table
|
11 | 12 |
|
12 | 13 | import cmd2
|
13 | 14 |
|
14 |
| -CITY_HEADERS = ['Country Flag', 'City', 'Country', '2025 Population'] |
15 |
| - |
| 15 | +CITY_HEADERS = ['Flag', 'City', 'Country', '2025 Population'] |
16 | 16 | CITY_DATA = [
|
17 |
| - [ |
18 |
| - "🇯🇵", |
19 |
| - "Tokyo (東京)", |
20 |
| - "Japan", |
21 |
| - 37_036_200, |
22 |
| - ], |
23 |
| - [ |
24 |
| - "🇮🇳", |
25 |
| - "Delhi", |
26 |
| - "India", |
27 |
| - 34_665_600, |
28 |
| - ], |
29 |
| - [ |
30 |
| - "🇨🇳", |
31 |
| - "Shanghai (上海)", |
32 |
| - "China", |
33 |
| - 30_482_100, |
34 |
| - ], |
35 |
| - [ |
36 |
| - "🇧🇩", |
37 |
| - "Dhaka", |
38 |
| - "Bangladesh", |
39 |
| - 24_652_900, |
40 |
| - ], |
41 |
| - [ |
42 |
| - "🇪🇬", |
43 |
| - "Cairo (القاهرة)", |
44 |
| - "Egypt", |
45 |
| - 23_074_200, |
46 |
| - ], |
47 |
| - [ |
48 |
| - "🇪🇬", |
49 |
| - "São Paulo", |
50 |
| - "Brazil", |
51 |
| - 22_990_000, |
52 |
| - ], |
| 17 | + ["🇯🇵", "Tokyo (東京)", "Japan", 37_036_200], |
| 18 | + ["🇮🇳", "Delhi", "India", 34_665_600], |
| 19 | + ["🇨🇳", "Shanghai (上海)", "China", 30_482_100], |
| 20 | + ["🇧🇩", "Dhaka", "Bangladesh", 24_652_900], |
| 21 | + ["🇪🇬", "Cairo (القاهرة)", "Egypt", 23_074_200], |
| 22 | + ["🇪🇬", "São Paulo", "Brazil", 22_990_000], |
53 | 23 | ]
|
54 | 24 |
|
55 |
| -COUNTRY_HEADERS = ['Flag', 'Country', '2025 Population', 'Area (M km^2)', 'Density (/km^2)'] |
56 |
| - |
| 25 | +COUNTRY_HEADERS = [ |
| 26 | + 'Flag', |
| 27 | + 'Country', |
| 28 | + '2025 Population', |
| 29 | + 'Area (M km^2)', |
| 30 | + 'Density (/km^2)', |
| 31 | + 'GDP (million US$)', |
| 32 | + 'GDP per capita (US$)', |
| 33 | +] |
57 | 34 | COUNTRY_DATA = [
|
58 |
| - [ |
59 |
| - "🇮🇳", |
60 |
| - "India", |
61 |
| - 1_463_870_000, |
62 |
| - 3.3, |
63 |
| - 492, |
64 |
| - ], |
65 |
| - [ |
66 |
| - "🇨🇳", |
67 |
| - "China", |
68 |
| - 1_416_100_000, |
69 |
| - 9.7, |
70 |
| - 150, |
71 |
| - ], |
72 |
| - [ |
73 |
| - "🇺🇸", |
74 |
| - "United States", |
75 |
| - 347_276_000, |
76 |
| - 9.4, |
77 |
| - 38, |
78 |
| - ], |
79 |
| - [ |
80 |
| - "🇮🇩", |
81 |
| - "Indonesia", |
82 |
| - 285_721_000, |
83 |
| - 1.9, |
84 |
| - 152, |
85 |
| - ], |
86 |
| - [ |
87 |
| - "🇵🇰", |
88 |
| - "Pakistan", |
89 |
| - 255_220_000, |
90 |
| - 0.9, |
91 |
| - 331, |
92 |
| - ], |
93 |
| - [ |
94 |
| - "🇳🇬", |
95 |
| - "Nigeria", |
96 |
| - 237_528_000, |
97 |
| - 0.9, |
98 |
| - 261, |
99 |
| - ], |
| 35 | + ["🇮🇳", "India", 1_463_870_000, 3.3, 492, 4_187_017, 2_878], |
| 36 | + ["🇨🇳", "China (中国)", 1_416_100_000, 9.7, 150, 19_231_705, 13_687], |
| 37 | + ["🇺🇸", "United States", 347_276_000, 9.4, 38, 30_507_217, 89_105], |
| 38 | + ["🇮🇩", "Indonesia", 285_721_000, 1.9, 152, 1_429_743, 5_027], |
| 39 | + ["🇵🇰", "Pakistan", 255_220_000, 0.9, 331, 373_072, 1_484], |
| 40 | + ["🇳🇬", "Nigeria", 237_528_000, 0.9, 261, 188_271, 807], |
| 41 | + ["🇧🇷", "Brazil", 212_812_000, 8.5, 25, 2_125_958, 9_964], |
| 42 | + ["🇧🇩", "Bangladesh", 175_687_000, 0.1, 1_350, 467_218, 2_689], |
| 43 | + ["🇷🇺", "Russia (россия)", 143_997_000, 17.1, 9, 2_076_396, 14_258], |
| 44 | + ["🇪🇹", "Ethiopia (እትዮጵያ)", 135_472_000, 1.1, 120, 117_457, 1_066], |
100 | 45 | ]
|
101 | 46 |
|
102 | 47 |
|
@@ -136,12 +81,12 @@ def do_cities(self, _: cmd2.Statement) -> None:
|
136 | 81 | def do_countries(self, _: cmd2.Statement) -> None:
|
137 | 82 | """Display the countries with the largest population."""
|
138 | 83 | table = Table(show_footer=False)
|
139 |
| - table.title = "Largest Countries by Population 2025" |
140 |
| - table.caption = "Data from https://worldpopulationreview.com/" |
| 84 | + table.title = "10 Largest Countries by Population 2025" |
| 85 | + table.caption = "Data from https://worldpopulationreview.com/ and Wikipedia" |
141 | 86 |
|
142 | 87 | for header in COUNTRY_HEADERS:
|
143 | 88 | justify = "left"
|
144 |
| - if 'Population' in header or 'Density' in header: |
| 89 | + if any(term in header for term in ['Population', 'Density', 'GDP']): |
145 | 90 | justify = "right"
|
146 | 91 | if 'Area' in header:
|
147 | 92 | justify = "center"
|
|
0 commit comments