In this lab, we're going to be designing and writing a program that converts text into pirate speech.
Task 1: Program Structure
We start by considering the big picture: the entire program. Your program should be written as a combination of functions, without any code written outside of a function except for calling your main method, which will be further described in task 3.
Outline your program in a google doc according to the following specifications:
- Replace at least three words with their pirate equivalents (ignoring case). Some possibilities are:
- Replace "hello" with "ahoy"
- Replace "friend" with "matey"
- Replace "stop" with "avast"
- List some example inputs, data that you could give your program, and corresponding outputs, the results when the program is given that input.
- What functions will make up this program? Consider the fact that your program needs input, processing, and output. Each function should have a single purpose and contain all the code necessary to fulfill that purpose. When creating functions, consider the program as a whole; the functions are the pieces that together make the program run.
Task 2: Functions and the Design Recipe
Now that we know what functions we want in the code, each function needs its own outline. Each function gets:
- Example data
In a contract, we state what types of inputs and outputs the function has. Your example data should then match the input and output specifications given by the contract. To help you write your outline, we've provided a paper template. Using this template, fill in:
- function name
- function description
- function inputs: Provide the type of data, variable names, and examples. Remember that a function can have any number of inputs (including 0)
- function outputs: Provide the type of data and examples. A function can have 0 or 1 outputs
Task 3: Write the Code
Building on the outlines you wrote in the previous two tasks, write the program.
If you want to more words to your translator, feel free to make some up or use this pirate dictionary.
When you hit run on a program, it should run a main method, which calls all of your other functions. Python does not explicitly require you to run a main method, but it's good practice. The main method marks the entry point of the program. Here is commented code for the main method format that we'd like you to use in this class:
#We define a function with the name main and no inputsdef main():#Your code goes here!#When the program is run in standard formatting,#the __name__ field will be main, so the program will run the main methodif __name__ == "__main__":main()#Remember to comment your code :-)
Task 4: Test the Code
Run your program in the command line. Use the texts you wrote in the first task to make sure that your program works properly. Are there cases where it doesn't work right? Try to come up with types of text that could break the code. Does it still work if there are no words that need to be replaced? What about if the words are capitalized?
Once you're done, please check off your lab with a TA or share your file with firstname.lastname@example.org by midnight, 3/7. You'll be using this code for the next activity, so be sure to save it under a name that you'll remember.