CSC 221: Introduction to Programming
Fall 2013

HW 3: Python Functions

This assignment will involve writing several Python functions. You should save all of your functions in a single Python module named lastnameFuncs (where lastname is your last name). The module should have a comment block at the top, containing the file name, your name, the date, and a brief description. Each function should also have a doc string that describes it behavior.

This assignment is to be completed on your own, with assistance from the instructor as needed.

1. HW2 Rewrites

For the first part of this assignment, you will rewrite code from HW2 in function form. In particular, you will repackage your code into the following functions:

2. Random Sequences

The following Python function can be used to generate a random 3-letter sequence:

import random ALPHABET = "abcdefghijklmnopqrstuvwxyz" def randomSequence(): """Returns a random 3-letter sequence.""" seq = random.choice(ALPHABET) + random.choice(ALPHABET) + random.choice(ALPHABET) return seq

Using your randomSequence function, it should be possible to approximate the number of words in the English language of a given length. For example, if you generated 10,000 random 4 letter sequences and determined that 100 of those sequences were words, you could estimate a 1/100 ratio of words to sequences. Since there are 264 = 456,976 different 4-letter sequences, you can estimate the number of 4-letter words as round((1/100) * 456,976) = 4,570.