Write a python program that creates a dictionary containing

Write a python program that creates a dictionary containing the U.S. states as keys and their capitals as values. (Use the Internet to get a list of the states and their capitals.) The program should then randomly quiz the user by displaying the name of a state and asking the user to enter that state\'s capital. The program should keep a count of the number of correct and incorrect responses. As an alternative to the U.S. states, the program can use the names of countries and their capitals.

Solution

import random
d = {\'Mississippi\': \'Jackson\', \'Iowa\': \'Des\', \'Oklahoma\': \'Oklahoma\', \'Delaware\': \'Dover\', \'Minnesota\': \'St.\', \'Illinois\': \'Springfield\', \'Rhode\': \'Island\', \'Moines\': \'South\', \'Arkansas\': \'Little\', \'Indiana\': \'Indianapolis\', \'New\': \'York\', \'Maryland\': \'Annapolis\', \'Louisiana\': \'Baton\', \'Idaho\': \'Boise\', \'Wyoming\': \'Cheyenn\', \'Arizona\': \'Phoenix\', \'North\': \'Dakota\', \'Michigan\': \'Lansing\', \'Kansas\': \'Topeka\', \'Utah\': \'Salt\', \'Virginia\': \'Richmond\', \'Oregon\': \'Salem\', \'Connecticut\': \'Hartford\', \'Montana\': \'Helena\', \'California\': \'Sacramento\', \'Massachusetts\': \'Boston\', \'Wisconsin\': \'Madison\', \'Vermont\': \'Montpelier\', \'Georgia\': \'Atlanta\', \'Pennsylvania\': \'Harrisburg\', \'Florida\': \'Tallahassee\', \'Hawaii\': \'Honolulu\', \'Kentucky\': \'Frankfort\', \'Alaska\': \'Juneau\', \'Nebraska\': \'Lincoln\', \'Rock\': \'New\', \'Ohio\': \'Columbus\', \'Alabama\': \'Montgomery\', \'South\': \'Dakota\', \'Colorado\': \'Denver\', \'Missouri\': \'Jefferson\', \'Washington\': \'Olympia\', \'Tennessee\': \'Nashville\', \'Rouge\': \'Texas\', \'Paul\': \'West\', \'Nevada\': \'Carson\', \'Maine\': \'Augusta\'}
st = [\'Alabama\', \'Montana\', \'Alaska\', \'Nebraska\', \'Arizona\', \'Nevada\', \'Arkansas\', \'Rock\', \'California\', \'New\', \'Colorado\', \'New\', \'Connecticut\', \'New\', \'Delaware\', \'North\', \'Florida\', \'North\', \'Georgia\', \'Ohio\', \'Hawaii\', \'Oklahoma\', \'Idaho\', \'Oregon\', \'Illinois\', \'Pennsylvania\', \'Indiana\', \'Rhode\', \'Iowa\', \'Moines\', \'Kansas\', \'South\', \'Kentucky\', \'Tennessee\', \'Louisiana\', \'Rouge\', \'Maine\', \'Utah\', \'Maryland\', \'Vermont\', \'Massachusetts\', \'Virginia\', \'Michigan\', \'Washington\', \'Minnesota\', \'Paul\', \'Mississippi\', \'Wisconsin\', \'Missouri\', \'Wyoming\']
count = 0
while(True):
   a = int(random.random()*50)
   print a
   ans = raw_input(\"What is the capital city for \"+d[st[a]]+\"?(q to quit):\")
   if ans == \"q\":
       print \"Your score is \"+str(count)
       break
   if ans == d[st[a]]:
       count += 1  

Write a python program that creates a dictionary containing the U.S. states as keys and their capitals as values. (Use the Internet to get a list of the states

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site