QuestionQuestion

1. Use turtle graphics to simulate a random walk of 1000 steps long. In your program, create a turtle named for you (for example, if your name is Tom, your the name of your turtle variable should be tom). At every step, you should choose an angle between 0 and 360 degrees at random and have your turtle turn by that angle and take 10 steps. For example, to make Tom's turtle turn a random angle and walk 10 steps, you could write:
angle = randrange(0,360)
tom.right(angle)
tom.forward(10)


2. Is it likely that a monkey at a typewriter, randomly choosing character, could write Hamlet?
Write a simulation to answer this question. That is, write a program that will randomly generate 100,000 strings of length 5 and count the number of strings that match "to be". You may assume that your strings are lower case letters and spaces only. That is, when you generate your string, you are choosing from the 27 characters:

[' ','a','b','c','d',...'y','z']

3. Write a simulation of the rolling of 2 six-sided dice. Your program should have a function that oneRoll() that returns the sum of rolling your dice. You may assume that each of the six sides is equally likely to be rolled (that is, the dice are "fair"). Run your simulation 10,000 times and report the frequency that each sum occurred.
A sample run of your program should look something like (but not identical due to the randomness of the simulation):

2 : 292
3 : 536
4 : 810
5 : 1100
6 : 1428
7 : 1631
8 : 1439
9 : 1100
10 : 825
11 : 543
12 : 296

4. Write a simulation of the rolling of 2 dice: 1 four-sided die and 1 eight-sided die. That is, the first die has four sides, and you can roll, with equal probability: 1,2,3, or 4. The second die has eight sides, and you can roll with equal probability: 1, 2, 3, 4, 5, 6, 7, or 8. Your program should have a function that oneRoll() that returns the sum of rolling your dice. Run your simulation 10,000 times and report the frequency that each sum occurred.
A sample run of your program should look something like (but not identical due to the randomness of the simulation):

2 : 308
3 : 629
4 : 932
5 : 1231
6 : 1230
7 : 1242
8 : 1343
9 : 1198
10 : 938
11 : 617
12 : 332

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

mport random

def oneRoll():
    die1 = random.randrange(1,7)
    die2 = random.randrange(1,7)
    return die1+die2

count = [0]*11
for i in range(10000):
    result = oneRoll()
    if result == 2:
       count[0] = count[0]+1
    elif result == 3:
       count[1] = count[1]+1
    elif result == 4:
       count[2] = count[2]+1...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats