Using Python!!! Write a function splitter that takes a string as an argument and
ID: 3793847 • Letter: U
Question
Using Python!!! Write a function splitter that takes a string as an argument and then returns the new version of that string. The original string that will be passed to the function consists of a sentence in which all of the words are run together but the first character of each word is uppercase. The returned version changes the sentence so that the words are separated by spaces and only the first word starts with an uppercase letter. For example, if StopAndSmellTheRoses. is passed to this functions, the function returns Stop and smell the roses.
Explanation / Answer
def splitter(s):
l = len(s)
returnString = ""
for i in range(l):
if i != 0:
if s[i] >='A' and s[i] <= 'Z':
returnString = returnString + " "
returnString = returnString+ s[i].lower()
else:
returnString = returnString+s[i]
else:
returnString = returnString+s[i]
return returnString;
print(splitter("StopAndSmellTheRoses"))
OUtput:
sh-4.3$ python3 main.py
Stop and smell the roses
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.