Write a python program and add a function named words_and_sents() to it. This function takes a string parameter called text. Your function should count and print the total number of words and sentences in the text. Assume that every word in the text is a substring followed by a space character “ “. Also, assume that every sentence in the text is a string containing one or more words and must end with a “.” or “?” character. Finally, capitalize each sentence (i.e., convert the first letter to uppercase) and print them on separate lines. See the sample output below.
Write a python program and add a function named words_and_sents() to it. This
function takes a string parameter called text. Your function should count and print the
total number of words and sentences in the text. Assume that every word in the text is a
substring followed by a space character “ “. Also, assume that every sentence in the text
is a string containing one or more words and must end with a “.” or “?” character. Finally,
capitalize each sentence (i.e., convert the first letter to uppercase) and print them on
separate lines. See the sample output below.
>>> text = "hello, here are some words. and some sentences. can
you count them."
>>> words_and_sents(text)
#sentences = 3, #words = 12
Printing sentences:
Hello, here are some words.
And some sentences.
Can you count them.

- Start
- define a function named "words_and_sents(text)" with string as a parameter
- split the spaces and count the number of words
- split the string from '.' or '?' for counting sentences
- print the count of sentences and words
- using loops traverse, capitalize and print the sentences
- Stop
Step by step
Solved in 4 steps with 2 images









