Julia Pais Anal • Official & Essential

# ---------------------------------------------------------------- # 4️⃣ Example usage # ---------------------------------------------------------------- if abspath(PROGRAM_FILE) == @__FILE__ # run only when this file is executed directly # Example: a tiny GDP table (USD per‑capita). In real life you would # load this from a CSV, an API, or a more complete dataset. sample_gdp = Dict( "FRA" => 41_463.0, "DEU" => 46_215.0, "JPN" => 40_247.0, "BRA" => 7_498.0, "USA" => 69_287.0 )

data = JSON3.read(String(resp.body))[1] # REST Countries returns an array; we take the first match

# Turn a dictionary of currencies (e.g. "USD"=>"name"=>"United States dollar","symbol"=>"$") into a vector of strings. function currencies_from_dict(dict::Dict) return [string(v["name"], " (", get(v, "symbol", "?"), ")") for (_, v) in dict] end julia pais anal

""" CountryReport

# ---- 2️⃣ Build the CountryInfo struct --------------------------- info = CountryInfo( get(data["name"], "common", "unknown"), get(data["name"], "official", "unknown"), get(data, "cca2", "??"), get(data, "cca3", "???"), get(data, "population", 0), get(data, "area", 0.0), get(data, "capital", String[]), get(data, "region", "unknown"), get(data, "subregion", "unknown"), languages_from_dict(get(data, "languages", Dict())), currencies_from_dict(get(data, "currencies", Dict())), get(data["flags"], "png", "") ) info.population / info.area_km2 : missing

if resp.status != 200 error("Could not fetch data for \"$(name_or_code)\" (HTTP $(resp.status)).") end

# 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 "United States dollar"

# ---- 3️⃣ Compute derived metrics -------------------------------- density = info.area_km2 > 0 ? info.population / info.area_km2 : missing