|
1 | 1 | # 9.7 - Challenge: Capital City Loop
|
2 | 2 | # Solution to challenge
|
3 | 3 |
|
4 |
| - |
5 |
| -from capitals import capitals_dict |
6 | 4 | import random
|
7 | 5 |
|
| 6 | +capitals_dict = { |
| 7 | + "Alabama": "Montgomery", |
| 8 | + "Alaska": "Juneau", |
| 9 | + "Arizona": "Phoenix", |
| 10 | + "Arkansas": "Little Rock", |
| 11 | + "California": "Sacramento", |
| 12 | + "Colorado": "Denver", |
| 13 | + "Connecticut": "Hartford", |
| 14 | + "Delaware": "Dover", |
| 15 | + "Florida": "Tallahassee", |
| 16 | + "Georgia": "Atlanta", |
| 17 | + "Hawaii": "Honolulu", |
| 18 | + "Idaho": "Boise", |
| 19 | + "Illinois": "Springfield", |
| 20 | + "Indiana": "Indianapolis", |
| 21 | + "Iowa": "Des Moines", |
| 22 | + "Kansas": "Topeka", |
| 23 | + "Kentucky": "Frankfort", |
| 24 | + "Louisiana": "Baton Rouge", |
| 25 | + "Maine": "Augusta", |
| 26 | + "Maryland": "Annapolis", |
| 27 | + "Massachusetts": "Boston", |
| 28 | + "Michigan": "Lansing", |
| 29 | + "Minnesota": "Saint Paul", |
| 30 | + "Mississippi": "Jackson", |
| 31 | + "Missouri": "Jefferson City", |
| 32 | + "Montana": "Helena", |
| 33 | + "Nebraska": "Lincoln", |
| 34 | + "Nevada": "Carson City", |
| 35 | + "New Hampshire": "Concord", |
| 36 | + "New Jersey": "Trenton", |
| 37 | + "New Mexico": "Santa Fe", |
| 38 | + "New York": "Albany", |
| 39 | + "North Carolina": "Raleigh", |
| 40 | + "North Dakota": "Bismarck", |
| 41 | + "Ohio": "Columbus", |
| 42 | + "Oklahoma": "Oklahoma City", |
| 43 | + "Oregon": "Salem", |
| 44 | + "Pennsylvania": "Harrisburg", |
| 45 | + "Rhode Island": "Providence", |
| 46 | + "South Carolina": "Columbia", |
| 47 | + "South Dakota": "Pierre", |
| 48 | + "Tennessee": "Nashville", |
| 49 | + "Texas": "Austin", |
| 50 | + "Utah": "Salt Lake City", |
| 51 | + "Vermont": "Montpelier", |
| 52 | + "Virginia": "Richmond", |
| 53 | + "Washington": "Olympia", |
| 54 | + "West Virginia": "Charleston", |
| 55 | + "Wisconsin": "Madison", |
| 56 | + "Wyoming": "Cheyenne", |
| 57 | +} |
8 | 58 |
|
9 |
| -def capital_game(state, capital): |
10 |
| - while True: |
11 |
| - guess = input(f"What is the capital of '{state}'? ").lower() |
12 |
| - if guess == "exit": |
13 |
| - print(f"The capital of '{state}' is '{capital}'.") |
14 |
| - print("Goodbye") |
15 |
| - break |
16 |
| - elif guess == (capital).lower(): |
17 |
| - print("Correct! Nice job.") |
18 |
| - break |
19 |
| - |
| 59 | +state, capital = random.choice(list(capitals_dict.items())) |
20 | 60 |
|
21 |
| -state = random.choice(list(capitals_dict.keys())) |
22 |
| -capital = capitals_dict[state] |
23 |
| -capital_game(state, capital) |
| 61 | +while True: |
| 62 | + guess = input(f"What is the capital of '{state}'? ").lower() |
| 63 | + if guess == "exit": |
| 64 | + print(f"The capital of '{state}' is '{capital}'.") |
| 65 | + print("Goodbye") |
| 66 | + break |
| 67 | + elif guess == capital.lower(): |
| 68 | + print("Correct! Nice job.") |
| 69 | + break |
0 commit comments