资本测验在 For 循环中使用字典值

Capital Quiz Using Dictionary Values In A For Loop

我需要创建一个使用 5 个州和首都的测验,并要求用户回答匹配的首都。我无法弄清楚如何打印单个值或单个键以生成问题。正如我现在的代码,它打印出字典中的每个值。

我尝试了包括索引位置在内的各种方法,但它们只会导致出现错误消息。我假设在 Python.

中使用字典时索引位置不可用
states = {'Colorado':'Denver', 'Ohio':'Columbus', 
'Florida':'Tallahassee','Arizona':'Phoenix', 'Mississippi':'Jackson' }

for values in states:
    state = states.keys()
    capital = states.values()
    print('What is the capital of:', state)
    answer = input("Please type your answer: ")
    if (answer == capital):
        print("\n", "You have guessed correctly!")
        correct += 1
    else:
        print("\n", "Sorry the answer is", capital)
        incorrect += 1

我希望打印的状态是一个单独的状态,每个状态都被连续打印。然后提示用户输入资金。如果大写匹配,它应该收集它作为正确答案,否则它应该打印出正确的大写和不正确的错误消息。

尝试

states = {'Colorado':'Denver', 'Ohio':'Columbus',
'Florida':'Tallahassee','Arizona':'Phoenix', 'Mississippi':'Jackson' }
correct = 0;
incorrect = 0
for state in states:
    capital = states[state]
    print("\nWhat is the capital of:", state)
    answer = input("Please type your answer: ")
    if (answer == capital):
        print("You have guessed correctly!")
        correct += 1
    else:
        print("Sorry the answer is", capital)
        incorrect += 1
print("got",correct,"correct and",incorrect,"incorrect answer" )