Special Cases and Gotchas The getUppercase() function should work equally well whether the text parameter is in
lowercase or already in uppercase. Also, any non-letter characters aren't affected by the
getUppercase()
function.
Note that using the dictionary that maps lowercase letters to uppercase letters means our
program only works for the basic 26 letters of the English alphabet. Therefore, it can’t convert letters
with accent marks to uppercase, such as 'ñ' to 'Ñ', the way Python’s upper() string method can.
You would have to add every accented letter to the dictionary if you want it to be converted to
uppercase.
Now try to write a solution based on the information in the previous sections. If you still have
trouble solving this exercise, read the Solution Template section for additional hints.
Solution Template Try to first write a solution from scratch. But if you have difficulty, you can use the following
partial program as a starting place. Copy the following code from https://invpy.com/uppercase-template.py and paste it into your code editor. Replace the underscores with code to make a working program:
# Map the lowercase letters to uppercase letters. LOWER_TO_UPPER = {'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D', 'e': 'E', 'f': 'F', 'g':
'G', 'h': 'H', 'i': 'I', 'j': 'J', 'k': 'K', 'l': 'L', 'm': 'M', 'n': 'N', 'o': 'O',
'p': 'P', 'q': 'Q', 'r': 'R', 's': 'S', 't': 'T', 'u': 'U', 'v': 'V', 'w': 'W', 'x':
'X', 'y': 'Y', 'z': 'Z'}
def getUppercase(text):
# Create a new variable that starts as a blank string and will # hold the uppercase form of text: uppercaseText = ''
# Loop over all the characters in text, adding non-lowercase # characters to our new string: for character in ____:
if character in ____:
# Append the uppercase form to the new string: uppercaseText += ____[____]
else:
uppercaseText += ____
# Return the uppercase string: return ____
The complete solution for this exercise is given in Appendix A and https://invpy.com/uppercase.py.
You can view each step of this program as it runs under a debugger at https://invpy.com/uppercase-