60.7k views
5 votes
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 program should print out "Hello. My name is Joe. What is your name?".

Write in python.
8.8

1 Answer

4 votes

Answer:

def capitalize_sentences(string):

# Split the string into individual sentences

sentences = string.split('.')

# Iterate over each sentence and capitalize the first letter

capitalized_sentences = [sentence[0].upper() + sentence[1:] for sentence in sentences]

# Join the sentences together and add a period (.) at the end

output_string = '. '.join(capitalized_sentences) + '.'

return output_string

User Axnet
by
6.8k points