Montana Tech of The University of Montana
Computer Science Department

CSCI 135
Fundamentals of Computer Science I
Fall 2019



LAB ASSIGNMENT 5

The goal of this assignment is to practice using dictionaries in Python. You will be using a dictionary to translate text in your code. Be sure you pay attention to your header comment and other comments, your indentation and variable names, and careful use of whitespace.


Speaking "Pirate"
Have you ever tried to talk like a pirate? Me neither...

For this assignment, you are to write a program that takes interactive input in the form of a string. The program should display a string containing the pirate tranlsation of the input sentence. Use the table below to construct a translation dictionary. Note - you should use the dictionary data type that we discussed in class during lecture.

Name this program ToPirate.py.

TopicEnglishPirate Translation
Greetings hello avast
excuse arrr
People sir, boy, man matey
madam proud beauty
officer foul blaggart
Articles the th'
my me
your yer
is be
are be
Places restroom head
restaurant galley
hotel fleabag inn

Some test input cases are shown below:

For the input "Excuse me sir where is the restroom" your program would print:

Arrr me matey where be th' head
 
For the input "Hello madam would you care to join me for dinner in the restaurant" your program would print:

Avast proud beauty would you care to join me for dinner in th' galley
    
For the input "HELLO Madam would YOU care to join me for dinner in The restaurant" your program would print:

Avast proud beauty would you care to join me for dinner in th' galley
    

How do I get started? Think about how we went over building a program in class on Monday. Start by figuring out what is coming in to your program (input) and what is going out (output). I tend to start by making sure I can get the input into the program. Then I start trying to figure out how I can transform that input into the required output. Next I start programming the pieces that I can and running them as I write them to make sure they work. And when you get to the parts that you're not sure how to code, break the logic into smaller and smaller parts that you can write code for. And as you do this, test each part (you can look at variable values by using print statements, or even use print statements to see if parts of your code are being reached) as you go.

How do I do different operations on strings? Take a look at the StringDemo.py example that we had in lecture on Monday 9/9. There are examples of different ways of manipulating strings in that code. In addition, you should probably use str.split() to break the incoming sentence into a list of words.

How do I deal with punctuation? For this assignment, you don't need to handle punctuation. It might make your life, and your testing, easier if you eliminate punctuation from your input sentences.

I accidently named my program toPirate or Pirate or ... Is that okay? No. This will break our grading script. This is a surefire way to make your TA grumpy. Plus it is really easy to fix. You can either choose to "Save As" the correctly named file in the Idle editor, or you can right click on the file in File Explorer and choose "Rename".



Grading This programs is worth 30 points, so an easy assignment this week. You will be graded according to the following criteria:

Grade ItemToPiratePoints Earned
Program Compiles and Runs
10
Header Comment
4
Accepts User Input Interactively
4
Program Runs Correctly
4
First Letter of Output Capitalized
2
Capitalized Words to Lower Case
2
Uses Dictionary Data Type
4



Submission. Submit your program ToPirate.py via Moodle. Be sure your source file has the required header with your name, and a description of the program.

Page last updated: October 09, 2019