dimanche 27 septembre 2020

Python Dice Program, Random integer not changing

I am trying to write a small bit of code, that makes a number of throws of a dice and then records the number of 6's rolled. As you can imagine i'm using random.randint(1,6). However the random integer is simply repeated for each consecutive throw. I am guessing it could be the structure of the while loop I have, i'm a total newbie to this so any help would be much appreciated.

#import random module
import random

#introduce the program
print("a program to count the number of 6's thrown in a simulation of a dice being thrown 6000 times")

#declare the variables
max = int(6) #need to declare max number for the dice
min = int(1) #need to declare min number for the dice
throw = random.randint(1,6) #each throw of the dice generates a number
countThrow = 0 #count the number of throws
maxThrow = int(6) #max throw
sixRolled = 0 #count the number of 6's thrown

#while loop

while countThrow != maxThrow:
    countThrow = countThrow + 1
    print(throw)
    print("Number of rolls ", countThrow)

    if throw == 6:
        sixRolled = sixRolled + 1
        print("You have thrown a", throw)

    else:
        print("you have rolled a", throw, "roll again.")
        

print("You have rolled ", sixRolled, "6's in 6 throws")

Many thanks




Aucun commentaire:

Enregistrer un commentaire