Python Homework #7

Instructions:

Please finish the functions from today's class. Note to PD5: the findWord() function ended up being harder than I had intended, so I've replaced it with a couple easier problems.

You should make sure you test each function on at least 2 inputs.
  1. Write a function extractSlice(string, start, stop, step). string is a string; start, stop, and step are integers. This function should return a new string consisting of the characters from start (inclusive) to stop (exclusive). This function should pick every step-th character of the string.
    # extractSlice("hello", 1, 3, 1) -> "el"
    # extractSlice("hello", 0, 5, 1) -> "hello"
    # extractSlice("hello", 0, 5, 2) -> "hlo"
    # extractSlice("hello", 3, 0, -1) -> "lle"
    

  2. Write a function lastFirst(fullname). Fullname is a string with two names, separated by a space. This function should return a new string like "Lastname, Firstname". You should use the extractSlice function to express this. You may also copy and reuse your findLetter() function from the previous homework.
    # lastFirst("Grace Hopper") -> "Hopper, Grace"
    

  3. Write a function repeatFront(someString, n). someString is a string, n is an integer. This function should return a string consisting of the first n characters of someString, then the first n-1 chars, etc, down to just the first character.
    # repeatFront("Chocolate", 4) -> "ChocChoChC"
    # repeatFront("Chocolate", 1) -> "C"
    

  4. Write a function repeatBack(someString, n). Similarly to repeatFront, it should return the following:
    # repeatBack("Buh-Boing", 5) -> "Boingoingingngg"