擅长:python、mysql、java
<p>你可以创建一个所有问题的列表,然后根据难度进行必要的拼接。在</p>
<pre><code>def get_choices(difficulty):
choices = [
"1)1\n2)2\n3)3\n4)4\n5)5\n:",
"1)Peter Parker\n2)Tony Stark\n3)Bruce Wayne\n4)Thomas Wayne\n5)Clark Kent\n:"
]
if difficulty == 'easy':
choices = [c.split("\n")[:3] for c in choices]
return choices
elif difficulty == 'medium':
choices = [c.split("\n")[:4] for c in choices]
return choices
else:
return choices
</code></pre>
<p>如果您可以将每个单独的选择都作为一个列表元素,并有一个对应的解决方案,则会更简单。然后你可以得到正确的答案,洗牌其他答案,并自动分配数字。在</p>