Sentence Capitalizer
Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument is “hello. my name is Joe. what is your name?” the function should return the string “Hello. My name is Joe. What is your name?” The program should let the user enter a string and then pass it to the function. The modified string should be displayed.
Sentence Capitalizer Program Code:
def capitalizeSentences(string):
# Split the string into sentences
#using period ('.') as the delimiter
sentences = string.split('. ')
# Capitalize the first character of each sentence
capitalizeSentences = [sentence.capitalize() for sentence in sentences]
# Join the capitalized sentences back into a single string
modified_string = '. '.join(capitalizeSentences)
return modified_string
# Prompt and read a string from the user
string = input("Enter a string: ")
# Call the capitalize_sentences function
modifiedString = capitalizeSentences(string)
# Display the modified string
print("Modified string:", modifiedString)
Executed Output 1:
Enter a string: hello. my name is Joe. what is your name?
Modified string: Hello. My name is joe. What is your name?
Executed Output 2:
Enter a string: how are you?
Modified string: How are you?