Unit 3 Task 12 - Solution

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Solution - Task 12: Capital city lookup

← Back to task


One possible program:

capitals = {
    "france": "Paris",
    "japan": "Tokyo",
    "egypt": "Cairo",
    "brazil": "Brasilia",
}

while True:
    country = input("Country (or 'quit'): ").strip().lower()
    if country == "quit":
        break
    city = capitals.get(country)
    if city is None:
        print("Unknown country")
    else:
        print(city)