我到目前为止的代码是

for i in range(6):
    roll1 =int(random.randint(1,6))
    print ("You rolled",roll1)


我需要它像打印

you rolled 3,4,5,6,2


但是我的输出看起来像:

You rolled 4
You rolled 4
You rolled 1
You rolled 1
You rolled 6
You rolled 6

最佳答案

尝试这个:

from random import randint
print( "You rolled " + ",".join(str(randint(1,6)) for j in range(6)) )

10-06 14:41