Saint Louis University |
Computer Science 1300
|
Computer Science Department |
Topic: While Loops, Functions
Related Reading: Chapter 5.1-5.3
Due:
11:00am, Wednesday, 4 October 2017
Please make sure you adhere to the policies on academic integrity.
Exercise 5.9 on page 196 of the book.
Write a function acronym(phrase) that accepts a string as a parameter, and returns a new string that includes the first letter of every word in the original phrase, all in uppercase. For example, a call to acronym('Laughing out loud') should return the string 'LOL'.
Note well: your task here is to return the string to the caller. There should be no user interactions from this function.
Strings have many convenient behaviors, one of which is that you can test whether a pattern occurs in another string, using the syntax
pattern in originalwhich produces a boolean result.
We want you to implement this test from basic principles. Provide an implemenation of a function with calling signature
isSubstring(pattern, original)that returns True or False, depending on the given parameters. Furthermore, you must not rely on any of the built-in behaviors of the string class, other than the fact that you can determine their lengths and you can use indexing to retrieve a single character of a string at a given index. That is, you are allowed to use syntaxes such as len(original) or pattern[j], but you must not use any other features of the string class such as find, index, or slicing notation pattern[j:k]. Instead use control structures to look for the pattern yourself, presumably testing every possible placement of where it might occur within the original string, and then testing character-by-character to see if you find a match.
Exercise 5.25 on page 199 of the book.