将两个随机数相加

Adding two random numbers together

所以我无法将 2 个随机生成的数字加在一起。用户必须看到生成的两个随机数,然后计算机必须将它们相加并打印出来。谁能告诉我我做错了什么?

import random
import time

roll_again = "yes"

while roll_again == "yes" or roll_again == "y":
    min = 1
    max = 6
    print("Rolling the dices...")
    time.sleep(2)
    print("The values are...")
    time.sleep(2)
    dice1 = print(random.randint(min, max))
    dice2 = print(random.randint(min, max))

    usertotal = dice1 + dice2

在您的代码中,您向终端打印了随机数,您没有将它们存储在变量 dice1 和 dice2 中。您的代码无效。

dice1 = print(random.randint(min, max))
dice2 = print(random.randint(min, max))
usertotal = dice1 + dice2

您应该这样做:

dice1 = random.randint(min, max)
print(dice1)
dice2 = random.randint(min, max)
print(dice2)
usertotal = dice1 + dice2
print(usertotal)