Q:

Python program for single dice simulation

belongs to collection: Python miscellaneous programs

0

Here, we will be stimulating the occurrences of each dice face i.e. 1, 2, 3, 4, 5, 6. Simply we are going to use an inbuilt library called as random to call a random value from given set and thereby we can stimulate the occurrence value by storing the occurrence in the list ls of length 6 representing each face of the dice as ls[4] represents the occurrence of face 5.

    ls[0] - dice(1)
    ls[1] - dice(2)
    ls[2] - dice(3)
    ls[3] - dice(4)
    ls[3] - dice(5)
    ls[5] - dice(6)

Then using the library pylab, we can plot the value of each occurrence and can stimulate it.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

import random
import pylab as py

def roll():
    return random.choice([1,2,3,4,5,6])

ls = [0,0,0,0,0,0]
chance = [104, 203, 302, 401, 505, 646, 756, 855, 985, 4565, 6565]
for n in chance:
    for k in range(n):
        scr = roll() 
        ls[scr-1] = ls[scr-1] + 4/4



py.figure()
py.plot([1,2,3,4,5,6], ls)
py.ylim(0,5040)

for el in ls:
    print(el)

Output

slice simulation program's output

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python miscellaneous programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program for single biased dice simulation... >>
<< Histogram using Pylab in Python...