SD 212 Spring 2023 / Homeworks


This is the archived website of SD 212 from the Spring 2023 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

hw13: Imagine no possessives

  • Due before the beginning of class on Wednesday, February 8

It’s easy if you try!

Your task

For today’s homework you have a choice whether to write your solution in Python in a program poss.py or as a bash script poss.sh. Either way your program should do the same thing.

Your script or program should read in text from standard in, and modify it so that simple possessives are replaced with an “of” phrase. For example, the sentence

I stole Julie's armadillo and hid it in Robin's backpack.

would be changed into

I stole the armadillo of Julie and hid it in the backpack of Robin.

Specifically, any time a phrase like “WORDA's WORDB” appears, it should be changed to “the WORDB of WORDA”.

Your program doesn’t need to account for upper/lowercase or grammar or anything else like that. Keep it simple!

The last line of input will be just the word DONE. (This should still be printed back on the terminal. It’s just to help you know when to end the python program if you write it a certain way.)

Sample run

Here is how your program should work, if you write it in Python:

roche@ubuntu$ python3 poss.py
Have you been to Elvis's house?
Have you been to the house of Elvis?
My dog's food gets all over the house's carpets.
My the food of dog gets all over the the carpets of house.
Don't do anything with contractions!
Don't do anything with contractions!
DONE
DONE

In bash it should work exactly the same, except that the command-line to run your code would be

roche@ubuntu$ bash poss.sh

Hint: You will probably need to figure out how to escape a single quote character ' in your string. Consider two examples:

# python - use triple quotes!
r'''Don't go breakin' my heart'''
# bash - it's just ugly...
'Don'"'"'t go breakin'"'"' my heart'

Submit command

To submit files for this homework, run one of these commands:

submit -c=sd212 -p=hw13 poss.*
club -csd212 -phw13 poss.*