If you have not yet read Chapters 1-8, you need to do that first, before starting this exercise. However, this exercise is being assigned on 11/05/08, and according to the reading assigments posted on GauchoSpace, you should have read Chapters 1-8 by now.
By the time you have completed this exercise, you should be able to
In exercise ex10, step 0 we downloaded the Swampy.1.1 software to your computer. Somwhere on your N drive, USB stick, or your computer, you should still have the swampy.1.1 folder, e.g.
| Example Folder Names | |
|---|---|
| Mesa Lab (Windows) |
N:\CS5NM\swampy.1.1 N:\cs5nm\swampy.1.1 |
| Mac | /Users/yourname/CS5NM/swampy.1.1 |
| Windows (your own computer) |
C:\CS5NM\swampy.1.1 |
| Flash Drive | F:\CS5NM\swampy.1.1 |
If you can't find this folder on your computer, then revisit step 0 of ex10 to download it.
If you don't have a folder like this (with a nice short name), create one now.
If you are not sure how to do that, ask your TA or your Instructor for help.
Inside your swampy.1.1 folder (wherever that is on your computer), there should be a file called words.txt, and you'll need that file in this exercise.
So locate it now to be sure it is there. In this picture below, you can see it in the bottom row, second from the left:

If it is not there, ask your TA or instructor for help.
Open a shell window in IDLE so that you have the >>> prompt.
Also, open a web window to Chapter 9 of the textbook.
Try the commands there. You'll probably find that if you just type fin = open('words.txt') as shown there, you'll get an error:
>>> fin = open("words.txt")
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
fin = open("words.txt")
IOError: [Errno 2] No such file or directory: 'words.txt'
>>>
The reason is that Python is not looking in the right place for "words.txt". To fix this, we can use string concatenation—something we've learned about in lecture, and from reading the textbook.
Define a variable that contains the location of your swampy.1.1 folder, like this. Be sure the name ends in a forward slash (/).
>>> swampy = "/Users/pconrad/CS5NM/swampy.1.1/"
Note: If you are on Windows, be sure to use forward slashes (/), even though Windows usually uses backslashes in filenames (\). As an example, you might have this on Windows:
>>> swampy = "C:/CS5NM/swampy.1.1/"
Once you've defined the variable swampy with an assignment statement like this,
if you then type swampy+"words.txt", you'll get something like this
(through the magic of string concatenation):
>>> swampy + "words.txt"
'/Users/pconrad/CS5NM/swampy.1.1/words.txt' >>>
Once that is done, from then on, when you see open("words.txt") in the textbook, if you substitute open(swampy+"words.txt") instead, you should get a better result—one that matches the textbook. For example:
>>> fin = open(swampy+"words.txt") >>>
If you are having trouble with this step, you can ask your instructor or TA for help—but if he/she is not immediately available, don't worry. You can continue with the rest of this exercise and even turn in your work—you don't have to fix any problem with words.txt right now. You will need to fix it before you can do all of the stuff in Chapter 9, and you will need it for a future exercise—but you can work through large parts of Chapter 9 (including everything you need to complete ex12) without finishing that right now.
The links below take you to Chapter 4 of the textbook (either link should work):
Once you've opened up this Chapter, just follow the instructions in the Chapter.
Be sure to read the paragraphs of text as well as the code carefully.
Try the exercises given. The solutions to many are given.
Did you actually try the exercises, or just skim through them? If you didn't really try the exercises
This is not an "optional" step. The textbook is not designed for "passive" reading. You cannot learn to swim by just "reading about Michael Phelps". You have to actually get into the water.
In the same way, you need to really try to program in order to learn about programming.
One of the functions given in Chapter 9 is this one, a function that checks whether a word contains the letter e:
def has_no_e(word):
for letter in word:
if letter == 'e':
return False
return True
The link given below contains a file that shows how we can use check_expect to test this function:
http://www.cs.ucsb.edu/~pconrad/cs5nm/08F/ex/ex12/hasNoETest.py
Note that the function fails one of the tests!
Before submitting on Gauchospace:
(e.g. ex12TerryKrautner.py, ex12PrasidDasgupta.py)
20 pts: naming and submitting files correctly
20 pts: correctly fixing the function so that all the tests pass
Ex12 is due Wednesday 11/12 at 5pm, and you are encouraged to complete it by then (to help you prepare for the exam on Wednesday 11/14)
However, it will be accepted through Tue 10/18 at 5pm without penalty.