Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Professor Stewart's Hoard of Mathematical Treasures, lan Stewart writes: It is said that if a monkey sat at a typewriter and kept hitting keys

image text in transcribed

In Professor Stewart's Hoard of Mathematical Treasures, lan Stewart writes: It is said that if a monkey sat at a typewriter and kept hitting keys at random, then eventually it would type the complete works of Shakespeare. This statement dramatises two things about random sequences: anything can turn up, and, therefore, the result need not appear random. The infinite monkey theorem goes further, and states that, if the monkey keeps typing for ever, then the probability that it will eventually type any given text is 1. Write a Python program to test this theorem. Your program should be run like so: python monkey-py ROM 1000000 The string argument is the text that you are hoping that the monkey will type; you may assume that the string is always in all caps. The integer argument is the number of times that the monkey types a random string having the same length as the string argument. In the example above, the monkey will type 1000000 3-letter words and your program will count the number of times the monkey types the string 'ROM' Your program should generate output that resembles the following: python monkey.py R 1000 The string R was typed 33 times. python monkey.py ROM 1000000 The string ROM was typed 60 times. python monkey.py ROMEO 1000000 The string ROMEO was typed 0 times

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

Step: 3

blur-text-image

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

=+What benefits are there in direct mail?

Answered: 1 week ago