This assignment is to be done with your teammate (if you have one).
An important and common use for computer science ideas is for translating or converting text from one form, or one language, to another. Tools like Google Translate will convert text from one language to another. Compilers convert computer programs from one programming language to another. For this assignment, you'll create a computer translator that will take text and convert it to pirate-speak. You'll be ready to go for International Talk Like A Pirate Day!
Your mission is to create a program to convert English to Pirate. Create a directory called pirate for your code, and name your program pirate.py. Specifically, here are some rules to follow:
Replace words as follows. hello -> ahoy; hi -> yo-ho-ho; my -> me; friend -> bucko; sir -> matey; miss -> proud beauty; stranger -> scurvy dog; officer -> foul blaggart; where -> whar; is -> be; the ->th'; you -> ye; old -> barnacle covered; happy -> grog-filled; nearby -> broadside; restroom -> head; restaurant -> galley; hotel -> fleabag inn. Feel free to add more if you like, but embellish this later: this is the easy part. You might want to get this working with just a few words, do the rest of the assignment, then come back to finish this for fun.
If a word begins with a capital letter, then when you translate it, it should also begin with a capital letter. Ignore the case of the rest of the word. In other words, translate "Where" / "WHERE" / "WhErE" / "WhERE" / etc. as "Whar", but translate "where" / "wHERE" / "wHeRe" / "wHere" / etc. as "whar". You should only output "Whar" or "whar" as a translation for any form of "where" -- none of the other letters in "Whar" or "whar" should ever be capitalized apart from possibly the first. (You should definitively not do this by testing individually for all possible ways the word "WhErE" might appear. You'll have over 1000 cases for "restaurant" if you do it that way.)
(Optional, for fun) Pirates have a habit of saying "Arrr" a lot. Get your translator to randomly insert "Arrr." between sentences. Anytime you encounter the end of a sentence (as denoted by a period, question mark, or exclamation point), decide with a 50/50 chance whether to insert an "Arrr."
Separating the words from the punctuation is kind of tricky in Python. Python makes it easy when things you want to read are separated by spaces and newlines, not punctuation. Therefore, your input should have spaces between anything you want Python to read in separately, such as:
Hello , sir ! I'm glad you are now my friend; you're no longer a stranger .
Create your input in a file called source.txt. Your program should read your input, and print out to the terminal window the pirate-translated version of your text. Just to get you started, this spacedWords.py program reads in a file and then prints out space-delimited words one-by-one, so that in principle you could do something with each word if you wished. Feel free to take a look and use this if it is helpful, but remember to type in yourself any code that you use (copying and pasting with the mouse tends to make you skip actually learning it, whereas retyping it seems to get it to sink in better.)
If you can get everything above working correctly, you will get full credit for this assignment. However, if you want to, feel free to try to get it working without needing to put spaced between words and punctuation. This separateWords.py program is much like spacedWords.py above, but separates words whenever the text transitions from a "word character" (i.e., a letter) to a "non-word character", or vice-versa. You're not responsible for knowing how the weird delimiter stuff works in this program, though I'm happy to explain it if anyone asks.
When finished, use Moodle to submit your code. Indicate in program comments the names of both authors (you and your partner), as well as roughly what fraction of the time each team member spent "driving" at the keyboard. You should be working to give all team members approximately the same amount of time driving.
Good luck, and have fun! Remember that lab assistants are available in the evenings in CMC 306 to help out if you need it.