我正在尝试创建一个掷骰子器,我可以调整掷骰子的数量,并在此基础上调整它输出的数字



如标题中所述,我正在创建一个掷骰子器,让用户在不限制骰子数量的情况下决定他们想要掷多少骰子。到目前为止,我已经将其发展到可以掷骰子的阶段,然后打印其中一个骰子的结果,但我不知道如何让它显示多个骰子变量的输出并打印它们,但我不知道这是否可能

import sys
h = 0
r = input('Would you like to roll the dice [y/n]?n')
while r != 'n':
if r == 'y':
m = input('What do you want to be able to role up ton')
t = input('How many times do you want to want to roll the dicen')
for h in range(int(t)):
d = random.randint(1, int(m))
h = h+1
print(d)
question = input('Would you like to roll the dice [y/n]?n')
else:
print('Invalid response. Please type "y" or "n".')
question = input('Would you like to roll the dice [y/n]?n')
print('Good-bye!')

如有任何帮助,将不胜感激

如注释中所述,在循环中移动print(d),您就会得到所需内容。此外,h = h+1是完全无用的,因为for循环的迭代是自动的。

最新更新