# Use the following template. # Write a function that accepts a sentence input # in which all of the words are run together # but the first character of each word is uppercase. # Convert the sentence to a string in which # the words are separated by spaces # and only the first word starts an uppercase letter. # For example, the string "StudyAndDoMorePractice" # would be converted to "Study and do more practice" # There are many way to solve the problem. # This file shows one possible solution. # Try tracing through by hand / pythontutor -- step by step def convert_sentence(sentence): result = "" # write your code here word = "" for letter in sentence: if letter.isupper(): if len(word) > 0: if len(result) > 0: word = word.lower() result += word + " " word = "" word += letter result += word.lower() # concat the last word to the result return result # main in_sentence = "StudyAndDoMorePractice" expected_sentence = "Study and do more practice" test1 = convert_sentence(in_sentence) if test1 == expected_sentence: print("You correctly converted " + in_sentence + " to \"" + test1 + "\"") else: print("convert_sentence(" + in_sentence + ") should be \"" + expected_sentence + "\" + " " but you got \"" + test1 + "\". Please check your code.")