【发布时间】:2020-02-17 09:48:20
【问题描述】:
我正在尝试编写一个函数,它将我的输入作为骰子的数量,为该数量的骰子获取一个介于 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),但我只收到一个空列表。
【问题讨论】:
-
你永远不会调用那个函数...
-
我对 Python 还是很陌生,什么意思?
标签: python python-3.x list function anaconda