Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 5 In Professor Stewart's Hoard of Mathematical Treasures, lan Stewart writes: It is said that if a monkey sat at a typewriter and kept
Question 5 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 seq 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 ev 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 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. The actual counts might be somewhat different because the strings are generated randomly. The Wikipedia article on the infinite monkey theorem contains some interesting results; in particular, what happened when the theorem was tested using actual monkeys
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started