Write a function(preLetterCase) that accepts two parameters ( a string ,and a letter). The function must return the string with all characters before the first instance of the letter converted to lowercase and all other characters converted to uppercase. Hence, if the specified letter is the first character of the string then the entire string will be converted to uppercase. The new string should be returned by the function.
e.g.
def preLetterCase(string, letter):
for i in range(len(string)):
if string[i].lower() == letter.lower():
return string[:i].lower() + string[i:].upper()
return string
print(preLetterCase ("CAtCHa","a"))
print(preLetterCase ("Preteen","e"))
print(preLetterCase ("You've got this", "m"))
print(preLetterCase ("Keep trying", "k"))
Comments
Leave a comment