Assignment 2

2 minute read

Due: by the end of the calendar day on Wednesday, February 8, 2023

Assignment

In this assignment, you will complete the Infinite Monkey exercise you started in class.

When you are finished, you should have at least four different functions, including those named random_letter, random_text, score, and monkey_experiment. Put these (and any other functions you write) in a file called infinite_monkey.py.

Test your functions

One of the things you will be graded on in this assignment is your own testing of your code. To show that you did this, you must include a big comment at the top of your code that shows how you tested your code and what the results were - maybe something like this:

"""
#Here's the code I used to test the monkey_experiment function
print(monkey_experiment("methinks it is like a weasel",100000))
print(monkey_experiment("methinks it is like a weasel",100))
print(monkey_experiment("brevity is the soul of wit",100000))
print(monkey_experiment("to be",100000))
print(monkey_experiment("to be",200000))
print(monkey_experiment("to be",500000))

#here's the results I got when I ran these tests
('yetha  xqtynpxgfkkoaedweasf ', 8)
('ktsnmgoknxlkldupuce jgvnaael', 5)
('vfcmitu emgthe h svidavhhs', 7)
('lo be', 4)
('tf by', 3)
('toube', 4)

"""

Automated Testing

I have written some automated tests on codePost that will run each of the four functions random_letter, random_text, score, and monkey_experiment.

My code attempts to call your functions with the kinds of parameters given. It’s mostly checking that calling the functions doesn’t break the code, and it does some minor checking that you’re generating lots of different letters, that text is the appropriate length, etc. These are just a sanity check, it’s really important that you’re convinced that your code is doing the right thing from your own testing.

If the tests fail and don’t give you useful output, it could be that you don’t have functions with the right names, parameters, or return values. So, check for that first.

Ultimately, I will look at your code and your comment with the testing info, and I’ll assign points based on that.

Grading

This is an 8-point assignment. See the rubric from the syllabus. Additionally, you will lose points if you do not include the comment with your tests and their results.

How to turn it in

  • Put your code in a file called infinite_monkey.py and make sure you named the functions as described above.
  • Make sure your code works when you run it in VS Code when you run it in script mode.
  • After you’ve tested it, log into https://codepost.io/ and submit simple_search.py to Assignment 2: Infinite Monkey .