I am really confused with what I'm doing here I am not sure why it is not working for me. I can print out random rolls for numbers 1-6 but now I am trying to do two other things:
- Print out the average dice value of all the rolls
- Which is the most frequent side of the dice
import random
def rollDie(number):
rolls = [0] * 6
for i in range(0, number):
roll=int(random.randint(1,6))
rolls[roll - 1] += 1
return rolls
if __name__ == "__main__":
result = rollDie(50)
i = result
print (result)
print(i/6)
The first question you pose needs a bit of clarification; what is it exactly that you are looking for in the "average" value thrown? To answer your second question, the function you gave us conducts a number amount of dice rolls, saving them to a list corresponding to each die number. All you have to do to see the most popular face rolled is print the list and look for the largest number. Alternatively, you can use the
array.index( max( array ) )
to find the index or 'die face' of the most rolled face.To be more explicit what you should have is: