擅长:python、mysql、java
<p>如果要关联值,请使用dict:</p>
<pre><code>lst_questions = ['6+11', '3+3', '9+10', '2+7', '11+8', '9+3', '11+9', '3+3', '2+4', '7+4', '4+8', '3+9']
lst_reponses = [17, 6, 19, 9, 19, 12, 20, 6, 6, 11, 12, 12]
data = dict(zip(lst_questions,lst_reponses))
{'2+4': 6, '2+7': 9, '3+3': 6, '9+10': 19, '6+11': 17, '3+9': 12, '9+3': 12, '11+9': 20, '11+8': 19, '7+4': 11, '4+8': 12}
</code></pre>
<p>向用户提问并验证:</p>
<pre><code>from random import choice
# "3+2" etc.. keys and correct result as value
data = dict(zip(lst_questions, lst_reponses))
# get random key
question = choice(data.keys())
inp = raw_input("What is {}".format(question))
# is user answer match the value
if int(inp) == data[question]:
print("Well done")
else:
print("Incorrect")
</code></pre>