使用randint和while循环模拟骰子掷骰

时间:2019-08-15 17:20:36

标签: python

我正在创建一个简单的随机骰子掷骰,但是代码为每个掷骰打印相同的答案

from random import randint
x = randint(1, 6)

class Die():
    def __init__(self, sides):
        self.sides = 6

    def roll_die(self):
        print(x)

die_1 = Die(6)
roll_count = 0

while roll_count <= 10:
    die_1.roll_die()        
    roll_count += 1

我希望这些掷骰子是随机的,但是无论第一掷骰子(即4)如何,都是while循环中的每个答案

4
4
4
4
4
4
4
4
4
4

1 个答案:

答案 0 :(得分:2)

您只能“滚动”一次。您想在每次致电campaigns = client.campaigns.all(get_all=False, count=5) 时使用campaigns = client.campaigns.all({'since_send_time' : '2019-08-14T15:30:00+00:00'})

x = randint(1, 6)