Write python to output the list of results from calculating the mean score from 10 throws of a 6 sided dice run 5 times.
So throw a dice 10 times and calculate the mean and repeat this 5 times resulting in a list/array of 5 numbers.
Any Ideas?
What is your plan? Have you figured out how you can "throw a dice" in Python?
(Mar-14-2021, 10:11 PM)tjm Wrote: [ -> ]Write python to output the list of results from calculating the mean score from 10 throws of a 6 sided dice run 5 times.
So throw a dice 10 times and calculate the mean and repeat this 5 times resulting in a list/array of 5 numbers.
Any Ideas?
Have you tried something like this?
This should work. If you need clarification for how anything works, let me know.
#import the random library for dice roll
import random
#create the list
lst = []
#5 repetitions
for i in range(5):
#roll the die and calculate the mean
total = 0
for r in range(10):
roll = (random.randint(1,6))
total += roll
mean = total/10
#add the mean to the list
lst.append(mean)
print(lst)
Idea should be something like 'calculate average of 10 throws of 6-sided dice 5 times', implementation it can be:
from statistics import mean
from random import randrange
results = [mean(randrange(1, 7) for i in range(10)) for i in range(5)]