CPSC120A
Fundamentals of Computer Science I

Lab 18

Slicing

Use the command line to create a new directory called lab18 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.

Remove Character

If you've ever gotten to a movie so early that advertisements before the previews that are before the movie haven't started, then you've probably seen the actor name word jumble. They show an actor's name with the letters all mixed up. You have 30 seconds to figure out how to rearrange the letters to spell an actor's name. Writing a function that can solve the jumble requires a database of actor names, but creating the word jumble is easy. Writing the function to jumble the letters is easier with a function that can remove letters from a string.

Create a Python function called remove_character(text, index) in a file called word_jumble.py The function should have a parameter, text, that is a string of any length and a parameter, index that is the index of a character in text. The function should return a new string that is the same as the input string with the character at the specified index removed. The function should use string slicing to get the substring of all characters to the left of the character to remove and all characters to the right of the character to remove and return the concatenation of the two characters. For example, if the input text to the function is "spam" and the input index is 1, the function should return "sam". Be sure to write your own test cases that cover all boundary conditions.

Word Jumble

Create a Python function called jumble_word(text) in the word_jumble.py file. The function should have one parameter, text, a string of any length. The function should return a new string that contains all of the characters of the input string in random order. Use the remove_character function to repeatedly remove a random character and add it to the jumbled string. For example, if the input text to the function is "hamill" the function may return "millah" or "illmah" or "mahlil" or some other text where each letter occurs once. However, it would never return "haamil" or "lilahh" because some letters are duplicated or missing.

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only programs that have perfect style and flawless functionality will be accepted as complete.