随机数Python

时间:2019-06-21 21:22:45

标签: python random

我正在尝试构建一个程序,该程序将从2个骰子中提取随机数,并将其加在一起。用户将输入他们想要的号码。如果骰子中的数字不等于用户输入的数字,它应该循环播放,再次进行一次,并计数得出用户输入的数字所花费的次数。当前,数字循环并达到所需的数字,但是循环并没有停止。

from random import randrange

statement =(input("This program rolls two 6-sided dice until their 
sum is a given target value. Enter the target sum to roll for:"))

diceOne = randrange(0,6)+1
diceTwo = randrange(0,6)+1
DiceSum = diceOne + diceTwo
Rollcount = 0

while DiceSum != statement:
    diceOne = randrange(0,6)+1
    diceTwo = randrange(0,6)+1
    DiceSum = diceOne + diceTwo
    printout = print('Roll:',(diceOne),'and', 
    (diceTwo),'equals'(DiceSum))

0 个答案:

没有答案