jeudi 29 mars 2018

Random numbers are the same after every loop

My program is supposed to display a pair of dice for every roll, which works as planned. I'd like it to repeat multiple times but every time it repeats it's no longer random and just repeats the assigned number from line 2 and 3. If I roll a 2 and a 3, it repeats a 2 and 3 every time. How can I make it so that a new random number is assigned each time it loops?

import random
dice1 = random.randrange(1,6)
dice2 = random.randrange(1,6)

... [I cut out the code for displaying the dice]

def start():
    confirmation = input("Would you like to roll the dice? (Y/N): ")
    if confirmation == "Y" or confirmation == "y":
        print ("You've rolled:",dice1,"and", dice2), showdice()
        return start()
    else:
        print("Goodbye")
start()




Aucun commentaire:

Enregistrer un commentaire