 Python Programming Assignment

Subject Computer Science Python Programming

Question

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 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 = *11
for i in range(10000):
result = oneRoll()
if result == 2:
count = count+1
elif result == 3:
count = count+1
elif result == 4:
count = count+1...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Word Counter \$35.00
Computer
Science
Python
Programming
Word
Counter
Frequency
Usage
A Python Program for Personal Income Tax Form \$25.00
Python
Programming
Project
Tax Form
Tax Table
IRS 1040EZ Form
Wages
Salaries
Tips
Python Programming Assignment \$40.00
Python Programming
Computer Science
Function
Currency Converter
Program
Data Collection Script Using Python \$63.00
Computer Science
Programming
Python
Windows
DOS Shell Command
Scripts
Data Collection
Algorithms
Statements
Variables
Methods
SSID
Signal Strength
Information
Tables
Databases
Dictionaries and File IO \$75.00
Computer
Science
Python
Programming
Dictionaries
File
IO
ASCII
CSV
Database
Live Chats