制作一个字典,要求键名为:至少3个省份的名称键值为:对应的2019-2024年的各项经济统计数据(至少5个元素,比如说,GDP,人均GDP)利用String的format方法(或f方法),将这一数据输出为字符串,并输出到屏幕上。
时间: 2024-10-07 15:02:19 浏览: 27
首先,我们需要创建一个字典结构来存储中国各省份的经济数据,这里假设我们有三个省份(例如:广东、江苏、山东)以及他们在2019年至2024年的一些关键经济指标,如GDP、人均GDP等。
```python
province_stats = {
"广东": {
"GDP_2019": 108700,
"人均GDP_2019": 106100,
"GDP_2020": 118000,
"人均GDP_2020": 111600,
"GDP_2021": 124300,
},
"江苏": {
"GDP_2019": 101000,
"人均GDP_2019": 105800,
"GDP_2020": 116000,
"人均GDP_2020": 110700,
"GDP_2021": 128000,
},
"山东": {
"GDP_2019": 76400,
"人均GDP_2019": 71100,
"GDP_2020": 85300,
"人均GDP_2020": 75900,
"GDP_2021": 100000,
}
}
# 使用f-string格式化输出
for province, stats in province_stats.items():
formatted_string = f"省份:{province}\n\n以下是部分经济数据:\n"
for year, value in stats.items()[:5]: # 取前五个指标
if 'GDP' in year:
formatted_string += f"{year}: {value}亿元\n"
else:
formatted_string += f"{year}: {value}元\n"
print(formatted_string)
```
阅读全文
相关推荐
![md](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)