



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Files to submit: hw5.py Functions to include in hw5.py:
**1. pigLatin()
Look at the String methods in the Python documentation here: http://docs.python.org/lib/string-methods.html You might find these methods useful: lower() upper() startswith() Also, pay attention to string slicing: >>> text = "Yellow Jacket" >>> text[1] 'e' >>> text[1:] 'ellow Jacket' >>> text[0:3] 'Yel'
Include the answers to the following questions AS A COMMENT at the BOTTOM of your hw5.py file. Be sure to comment the answers out or your python code will NOT run. If your code does not run, you will receive a 0. All of the answers can be found by looking here: http://docs.python.org/lib/string-methods.html
The Python string method capitalize() returns a copy of the string with only its first character capitalized. We are going to write our own version of this built in method to understand better how it works. Write a function, myCapitalize() that takes in a single word as its parameter with the same functionality as the built in method, capitalize(). Sample Output: >>> "hello".capitalize() 'Hello' >>> "hELLo".capitalize() 'Hello' >>> myCapitalize("hello") 'Hello' >>> myCapitalize("hELLo") 'Hello' Note: The first two examples are using the built in method while the second two are using the function you write. You can check your function against the built in method in this way. Hint: You may find lower() and upper() to be helpful methods to use—you are most definitely allowed to use these.
We will write a simplified version of the startswith() method. (Look it up on the API for full functionality). Write a function, myStartsWith() that takes in two strings—a word and a prefix to look for in that word. If the prefix is the beginning of the word, return True. Otherwise, return False. Sample Output: >>> "Hi".startswith("h") False >>> "king".startswith("kings") False >>> "king".startswith("ki") True >>> "king".startswith("knight") False >>> myStartsWith("king", "kings") False >>> myStartsWith("king", "king") True >>> myStartsWith("king", "kong") False Hint: You may find string slicing (word[::]) and len() to be helpful.
Pick another method from the Python API and write your own version of it.
Be sure to name your files and functions exactly as indicated. READ THROUGH THE INSTRUCTIONS CAREFULLY. If you need help, be sure to come to office hours. Good Luck! Written/Adapted by Beth York, Fall 2007