Python Homework #9

Instructions:


You should make sure you test each function on at least 2 inputs.
  1. Write a function extractSandwich(text). text is a string. This function should return the portion of the string between the first and second occurence of "bread". If "bread" does not appear twice in the string, your function should return None. You should use findWordStartingAt(...) as a helper function to write this.
    # ("breadjambread") -> "jam"
    # ("olivebreadcheesebreadplate") -> "cheese"
    # ("justbreadbread") -> ""
    # ("butterbread") -> None
    # ("orange") -> None
    



  2. Python has functions chr and ord which can convert characters to numbers and back.
    ord("A") # 65
    ord("B") # 66
    ord("a") # 97
    chr(97) # "a"
    chr(ord("A") + 1) # "B"
    
    Remember: the uppercase and lowercase letters are in order.
    What would ord("A") - ord("a") evaluate to?
    What about ord("Q") - ord("q")

  3. Use chr and ord to write a function letterToUppercase(letter). letter is a single-character string. If letter is a lowercase letter, you should use chr() and ord() to calculate the corresponding uppercase letter. Otherwise, return the letter unchanged.
    # charToUppercase("a") -> "A"
    # charToUppercase("q") -> "Q"
    # charToUppercase("?") -> "?"
    # charToUppercase("A") -> "A"