Program:
#Changing a string to title case using title() function
def convertToTitle(string):
titleString = string.title();
print("The input string in title case is:",titleString)
userInput = input("Write a sentence: ")
#Counting the number of space to get the number of words
totalSpace = 0
for b in userInput:
if b.isspace():
totalSpace += 1
#If the string is already in title case
if(userInput.istitle()):
print("The String is already in title case")
#If the string is not in title case and consists of more than one word
elif(totalSpace > 0):
convertToTitle(userInput)
#If the string is of one word only
else:
print("The String is of one word only")
OUTPUT:
Write a sentence: good evening!
The input string in title case is: Good Evening!