Julia Pais Anal -

Returns a `CountryReport`. """ function analyze_country(name_or_code::AbstractString; gdp_table=nothing) # ---- 1️⃣ Pull the JSON payload --------------------------------- url = "https://restcountries.com/v3.1/name/" * HTTP.escapeuri(name_or_code) resp = HTTP.get(url; timeout=15)

* `gdp_table` – optional `DictString,Float64` mapping ISO‑3 codes to GDP per‑capita in USD. If supplied, the function also returns an “economic weight” = population × GDP/Capita. julia pais anal

# ---------------------------------------------------------------- # 2️⃣ Helper functions # ---------------------------------------------------------------- # Turn a dictionary of languages (e.g. "spa"=>"Spanish") into a vector of strings. languages_from_dict(dict::Dict) = collect(values(dict)) Returns a `CountryReport`

Fetches basic data for the given country from the REST Countries API, computes population density, and (optionally) merges a GDP‑per‑capita value from a user‑provided `gdp_table`. You can extend any of the steps (e

You can extend any of the steps (e.g., add more fields, plug in a different data source, or compute extra statistics). # -------------------------------------------------------------- # Country analysis feature for Julia # -------------------------------------------------------------- using HTTP using JSON3 using DataFrames # optional, only needed if you want tabular output using Statistics # for mean, median, etc. using Printf # for nice formatting

# Simple pretty‑printer for the report. function Base.show(io::IO, r::CountryReport) i = r.info @printf io "Country: %s (%s / %s)\n" i.name i.iso2 i.iso3 @printf io "Official name: %s\n" i.official_name @printf io "Capital: %s\n" join(i.capital, ", ") @printf io "Region / Subregion: %s / %s\n" i.region i.subregion @printf io "Population: %'d\n" i.population @printf io "Area: %'.2f km²\n" i.area_km2 @printf io "Population density: %'.2f people/km²\n" r.density @printf io "Languages: %s\n" join(i.languages, ", ") @printf io "Currencies: %s\n" join(i.currencies, ", ") @printf io "Flag: %s\n" i.flag_url if r.gdp_per_capita !== missing @printf io "GDP per capita (USD): $%'.2f\n" r.gdp_per_capita @printf io "Economic weight (pop × GDP/Capita): $%'.2f\n" r.economic_weight else @printf io "GDP data not supplied.\n" end end