对地下城与龙进行深入的测验

问题描述 投票:0回答:1

我一直在努力用随机题库进行测验,在该题库中,问题将能够增加许多不同的计数器(每个问题的返回内容将有所不同)。在下面,我显示了我到目前为止所拥有的内容以及两个示例问题,其中仅包含最终会出现的一些“反增长”。有没有一种方法可以将我遇到的问题放入银行,因此每次运行测验时,都会有50个左右的银行有20个不同的问题?]

barbarian_count = 0
bard_count = 0
cleric_count = 0
druid_count = 0
fighter_count = 0
monk_count = 0
paladin_count = 0
ranger_count = 0
rogue_count = 0
sorcerer_count = 0
warlock_count = 0
wizard_count = 0

STR_count = 0
DEX_count = 0
CON_count = 0
INT_count = 0
WIS_count = 0
CHA_count = 0

law_count = 0
chaos_count = 0
neutrallc_count = 0

good_count = 0
neutralge_count = 0
evil_count = 0

Acolyte_count = 0
Charlatan_count = 0
CriminalSpy_count = 0
Entertainer_count = 0
Folkhero_count = 0
Gladiator_count = 0
Guildartmerchant_count = 0
hermit_count = 0
knight_count = 0
noble_count = 0
outlander_count = 0
pirate_count = 0
sage_count = 0
sailor_count = 0
soldier_count = 0
urchin_count = 0


q1_answer = input ("Passion or Reason? \na) Passion \nb) Reason\n")

if q1_answer.lower() == "a":
    barbarian_count += 1
  bard_count += 1
  chaos_count += 1
elif q1_answer.lower() == "b":
    wizard_count += 1
  law_count += 1
else:
    print("sorry, try again.")


q2 = q2_answer = input ("Fame or Honor? \na) Fame \nb) Honor\n")

if q2_answer.lower() == "a":
    bard_count += 1
elif q2_answer.lower() == "b":
    paladin_count += 1
else:
    print("sorry, try again.")




if barbarian_count > wizard_count and barbarian_count > bard_count and barbarian_count > paladin_count:
    print("You have the heart of a barbarian")
elif wizard_count > barbarian_count and wizard_count > bard_count and wizard_count > paladin_count:
    print("You have the heart of a wizard")
elif bard_count > wizard_count and bard_count > paladin_count and bard_count > barbarian_count:
  print("You have the heart of a bard")
elif paladin_count > wizard_count and paladin_count > barbarian_count and paladin_count > bard_count:
  print("You have the heart of a paladin")

input('Press ENTER to exit')

我试图用类似的东西列出清单>

question_bank = [
  {
    'q1 = [q1_answer = input ("Passion or Reason? \na) Passion \nb) Reason\n")

if q1_answer.lower() == "a":
    barbarian_count += 1
elif q1_answer.lower() == "b":
    wizard_count += 1
else:
    print("sorry, try again."]'
  },
  {
    'q2 = q2_answer = input ("Fame or Honor? \na) Fame \nb) Honor\n")

if q2_answer.lower() == "a":
    bard_count += 1
elif q2_answer.lower() == "b":
    paladin_count += 1
else:
    print("sorry, try again.")'
  }
]


但是我认为已经意识到的列表不能那样工作。

有什么建议吗?我希望我可以将每个问题的每个完整脚本放到一个列表中,这样我就可以使用“ import random”和random.choice或random.sample来提取完整​​问题的脚本。

我一直在努力用随机题库进行测验,在该题库中,问题将能够增加许多不同的计数器(每个问题的返回内容将有所不同)。 ...

python python-3.x random counter
1个回答
0
投票

我认为使用random.sample是从问题主列表中选择随机问题的好方法。这是我想出的:

© www.soinside.com 2019 - 2024. All rights reserved.