我正在尝试编写一个函数,它将我的输入作为骰子数量,获取骰子数量在1,6之间的随机数,然后将这些数字附加到一个列表中。你知道吗
我尝试了不同的返回消息,但我似乎无法将其附加到列表中,也无法真正思考我的代码还能做些什么。你知道吗
terninger = []
def terning_kast(antal_kast = int(input("Hvor mange terningekast? "))):
for x in range(antal_kast, 0, -1):
resultat = random.randint(1, 6)
terninger.append(resultat)
return resultat
print(terninger)
我希望代码将随机数1,6附加到上面的列表中(terninger),但我只收到一个空列表。你知道吗
你的逻辑中有几点需要纠正。同时,以下可能是你想要的。你知道吗
if
__name__ == "__main__":
指示python解释器运行您的脚本(如果您要从同一模块执行)。如果您要从其他模块使用这个模块(导入),那么您不需要提到这个if
__name__ == "__main__":
您忘记调用函数=>;
terning_kast()
相关问题 更多 >
编程相关推荐