{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Exercise 1**:\n", "\n", "Lookup a country in [World Bank database](https://data.worldbank.org), and format a string showing the growth rate of GDP over the last 2 years." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The growth rate in 2018 was 1.3\n", "The growth rate in 2019 was 0.55\n" ] } ], "source": [ "germany_gdp_growthrate = {\n", " 2018: 1.3,\n", " 2019: 0.55\n", "}\n", "\n", "for (k, v) in germany_gdp_growthrate.items():\n", " print(f\"The growth rate in {k} was {v}\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_items([(2018, 1.3), (2019, 0.55)])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "germany_gdp_growthrate.items()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Exercise 2:**\n", "\n", "Using the country you chose from exercise one, create a dictionary with GDP, population, and life expectancy for the years 1980, 1990, 2005, 2015. The years should be the keys and each value should be another dictionary with keys `GDP`, `population`, and `life_expectancy`." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "germany_wb_data = {\n", " 1980: {\"GDP\": 950.2, \"population\": 78_000_000, \"life_expectancy\": 72.67},\n", " 1990: {\"GDP\": 950.2, \"population\": 78_000_000, \"life_expectancy\": 72.67},\n", " 2005: {\"GDP\": 950.2, \"population\": 78_000_000, \"life_expectancy\": 72.67},\n", " 2015: {\"GDP\": 950.2, \"population\": 78_000_000, \"life_expectancy\": 72.67},\n", "}" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | 1980 | \n", "1990 | \n", "2005 | \n", "2015 | \n", "
---|---|---|---|---|
GDP | \n", "950.20 | \n", "950.20 | \n", "950.20 | \n", "950.20 | \n", "
population | \n", "78000000.00 | \n", "78000000.00 | \n", "78000000.00 | \n", "78000000.00 | \n", "
life_expectancy | \n", "72.67 | \n", "72.67 | \n", "72.67 | \n", "72.67 | \n", "