Task-Throw a dice 10 Times - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Task-Throw a dice 10 Times (/thread-32900.html) |
Task-Throw a dice 10 Times - tjm - Mar-14-2021 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? RE: Task-Throw a dice 10 Times - deanhystad - Mar-14-2021 What is your plan? Have you figured out how you can "throw a dice" in Python? RE: Task-Throw a dice 10 Times - MattKahn13 - Mar-17-2021 (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. 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) RE: Task-Throw a dice 10 Times - perfringo - Mar-17-2021 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)] |