为什么这个掷骰子功能输出2?

2024-04-25 18:04:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图完成this挑战,但我被卡住了。你知道吗

这就是我目前所拥有的。除非我用args4和args6运行它,它会输出随机数。你知道吗

import random

def roller(rolls, sides):
    i = 0
    while i != rolls:
        x = random.randint(1, sides)
        i += 1
        return x

    lst = range(1, sides)
    lst = [str(i) for i in lst]

    for elem in lst:
        return elem + ": " + str(x)

print(roller((int(input("# of rolls: "))) ,(int(input("# of sides: ")))))

为什么使用与示例中相同的格式?为什么它只输出一个值?你知道吗


Tags: ofinforinputreturnrandomrollerthis