Python D&D 掷骰子程序只掷 D20,而不考虑用户输入?



我正在尝试用Python创建项目,今天的项目是桌面角色扮演游戏(如地下城&龙。我为D4到D100的每种类型的骰子定义了一个函数。我认为我使用基于用户输入的嵌套If/Elif语句正确地构建了while循环。然而,不管用户输入什么,只有D20可以滚动?D20函数是我的While循环中的第一个If语句,所以我猜测这一行特别有问题:

我是否以某种方式编写了这篇文章,无论用户输入了什么,任何输入都会满足第一个If语句,而不需要检查Elif语句?

While循环:

while not done:
diceroll = str(input("Roll the Dice! You can enter D4, D6, D8, D10, D12, D20, D100, or Custom. Q to exit:"))
print('You entered ' + str(diceroll) + ':')
if diceroll == 'd20' or 'D20':
rolld20()
elif diceroll == 'd12' or 'D12':
rolld12()
elif diceroll == 'd%' or 'D%' or 'd100' or 'D100':
rolld100()
elif diceroll == 'd10' or 'D10':
rolld10()
elif diceroll == 'd8' or 'D8':
rolld8()
elif diceroll == 'd6' or 'D6':
rolld6()
elif diceroll == 'd4' or 'D4':
rolld4()

我怀疑发生的事情是检查"D20"是否总是不为0(False(您需要标准化您的输入或添加其他检查

相关内容

最新更新