/* CapitalsDictionary.swift Copyright (c) Kari Laitinen http://www.naturalprogramming.com 2018-02-06 File created. */ import Foundation // First we create a dictionary in which countries and capitals // are stored as Key-Value pairs. Country name is the key. let countries_and_capitals = [ "Finland" : "Helsinki", "Usa" : "Washington", "Denmark" : "Copenhagen", "Afghanistan" : "Kabul", "Russia" : "Moscow", "England" : "London", "Italy" : "Rome", "France" : "Paris", "Spain" : "Madrid", "Portugal" : "Lisbon", "Chile" : "Santiago", "Japan" : "Tokyo", "Sweden" : "Stockholm", "Norway" : "Oslo", "Pakistan" : "Islamabad", "Iceland" : "Reykjavik", "Hungary" : "Budapest", "Holland" : "Amsterdam", "Belgium" : "Brussels", "Austria" : "Vienna", "Israel" : "Jerusalem" ] print( "\n This program may know the capital of a country." + "\n Type in the name of some country: ", terminator: "" ) var country_name = readLine()! // According to documentation on 2018-02-06 'capitalized' is an NSString // property. It seems to work when Foundation is imported. country_name = country_name.capitalized if let capital_name = countries_and_capitals[ country_name ] { print( "\n The capital of \( country_name ) is \( capital_name ).\n" ) } else { print( "\n Sorry, I do not know the capital of \( country_name ).\n" ) }