Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

# 4. RECURSIVE METHOD. Write a function called to_upper. It is passed a str obje

ID: 3832963 • Letter: #

Question

# 4. RECURSIVE METHOD. Write a function called to_upper. It is passed a str object,
# and returns a str object in which all of the lower case letter
# in the parameter string have been changed to upper case.
# You may NOT use the built-in method upper of the Python str class.
#
# For example:
# >>> s = 'CSC 242 Intro to Computer Science II'
# >>> s = to_upper(s)
# >>> s
'CSC 242 INTRO TO COMPUTER SCIENCE II'

def to_upper(word):
lower = 'abcdefghijklmnopqrstuvwxyz'
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# you might find it helpful to use d in your code below
d = dict()
for i in range(26):
d[lower[i]] = upper[i]
# continue here with your own code to complete the function
pass

# 5. RECURSIVE METHOD. Write a function called in_order, which returns True if a
# list of words is in lexicographical order (i.e., they
# appear in the same order in which they would appear in
# the dictionary). Do not use the sort function. Assume the
# words are all lower case. For example:
#
# >>> in_order(['apple', 'grape', 'grapefruit', 'orange', 'pear'])
# True
# >>> in_order(['apple', 'grape', 'pear', 'banana'])
# False
#

def in_order(words):
pass

Explanation / Answer

def to_upper(word):
if not word:
return ""
lower = 'abcdefghijklmnopqrstuvwxyz'
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# you might find it helpful to use d in your code below
d = dict()
for i in range(26):
d[lower[i]] = upper[i]
result = word[0]
if word[0] in d:
result = d[word[0]]
return result + to_upper(word[1:])

s = 'CSC 242 Intro to Computer Science II'
print(to_upper(s))

# code link: https://paste.ee/p/9g2oJ