vendredi 21 juin 2019

Random numbers Python [duplicate]

This question already has an answer here:

I'm trying to build a program that will take random numbers from 2 dice.It should add them together. The user will input the desired number they want to reach. If the numbers from the dice are not equal to the number inputted by the user, it should loop around, do it again and count the number of times it took to get to the number inputted by the user. Currently the numbers loop and reach the desired number but the loops does not stop.

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))




Aucun commentaire:

Enregistrer un commentaire