Skip to content

Commit 1f155a3

Browse files
committed
Clean-up capital city loop challenge
1 parent eafc628 commit 1f155a3

File tree

2 files changed

+62
-74
lines changed

2 files changed

+62
-74
lines changed
Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,69 @@
11
# 9.7 - Challenge: Capital City Loop
22
# Solution to challenge
33

4-
5-
from capitals import capitals_dict
64
import random
75

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+
}
858

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()))
2060

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

ch09-lists-tuples-and-dictionaries/capitals.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)