Python Forum
Task-Throw a dice 10 Times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Task-Throw a dice 10 Times
#1
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?
Reply
#2
What is your plan? Have you figured out how you can "throw a dice" in Python?
Reply
#3
(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)
Reply
#4
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)]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find how many times a user played an artist and how many times disruptfwd8 1 2,605 May-04-2018, 08:32 AM
Last Post: killerrex

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020