Hello,
I am trying to create a program that uses a dictionary to associate American states with their capitals. It has an interactive loop that exits when the user enters "quit". The user types the name of the state and the program responds with the state's capital.
I will show you what I have so far and then ask my question.
This is what I have:
def main():
staStr = raw_input("Enter the name of a state (Enter quit to exit): ")
cs = {"indianapolis":"indiana", "columbus":"ohio", "jackson":"mississippi",
"phoenix":"arizona", "honolulu":"hawaii", "richmond":"virginia",
"springfield":"illnois", "lincoln":"nebraska",
"boston":"massachuettes", "lansing":"michigan", "desmoines": "iowa",
"salem": "oregon"}
while staStr != "quit":
if cs.has_key(staStr):
cs.get(staStr, "quit")
print staStr
else:
print "No key matches! Try again!"
main()
I am not really sure how to associate each state with it's own capital. I know that dictionaries do not have any sequential order therefore I cannot number each element.
I am not really clear on how to do this . Also do I have my states and capitals backwards? Should I have my state as the "key" and my capital as the "value"?
Thanks for your input!