Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dice rolling odds The code shown will simulate rolling a single die (values from 1 to 2). Expand this code to simulate rolling a pair

Dice rolling odds The code shown will simulate rolling a single die (values from 1 to 2). Expand this code to simulate rolling a pair of 6 sided dice 1000 times, store the results in a list and display the percentage of time each roll occurs. If you would like to earn 10 points of extra credit, you may include a matplotlib plot showing a graph of your findings, the title of the graph must include your name (see example output below). Examples of creating graphs can be seen at matplotlib.org under examples.

import random

# List with two zeros to store results of a 2 sided dice roll.

rolls = [0]*2

# Roll random value in the range 1-2

dieRoll = random.randint(1,2)

rolls[dieRoll-1] += 1

dieRoll = random.randint(1,2)

rolls[dieRoll-1] += 1

dieRoll = random.randint(1,2)

rolls[dieRoll-1] += 1

print("Results: %s" % str(rolls))

The percentage can be calculated as the number of times a number was rolled divided by the total number of rolls. When rolling 1 die, the odds of all 6 possibilities should be about equal, but when rolling two dice it should not. For example rolling 7 is much more likely than 2 or 12 since there are more ways to get 7 (2+5, 3+4, etc...).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago