我正在嘗試做出多選(4個選擇)的問答遊戲。到目前爲止,我已經做了一個簡單的測驗,只包含一個問題。我無法圍繞索引問題的好方法。進行測驗,如何存儲問題?
該計劃是擴大我的測驗至少500個問題,並從問題池中隨機挑選一個問題。我應該如何構造它?
這是我在我的一個個問題的遊戲這麼遠:
def welcome(): #Introduction
print "Welcome to the quiz!"
print " "
print " "
def question(): # Question function
quest = { 'id' : 0, 'question' : "What is the capital of Belgium?" , 'a' : "Vienna" , 'b' : "Berlin" , 'c' : "Brussels" , 'd' : "Prague" , 'answer' : 'c'}
print quest['question']
print " "
print "A:", quest['a'],
print "B:", quest['b'],
print "C:", quest['c'],
print "D:", quest['d']
guess=raw_input("Your guess: ")
if guess == quest['answer']:
print " "
print "Correct!!!"
else:
print " "
print "Sorry, that was just plain wrong!"
welcome()
question()
你的詞典是一個良好的開端!現在製作一個這樣的詞典列表。然後你可以使用'random.choice'來選擇一個隨機問題。 – L3viathan