Question
Chapter 3 Assignment String Parsing In this exercise you will make use of Python the for-loop, if-else, or while loop constructs. Requirement: A customer is
Chapter 3 Assignment String Parsing
In this exercise you will make use of Python the for-loop, if-else, or while loop constructs.
Requirement:
A customer is asking you to parse up to 3 sentences containing any number of characters and provide a print out of the number of character in each sentence.
From the input, you will provide a report or output that indicates the total number of characters in the sentence. Characters include white space.
Therefore, when the user inputs a sentence and hits the return key, that sentence is then parsed and the output provides a count of the number of characters within the sentence.
You are allowed to parse anywhere from 0 to 3 sentences; any more than 3 and you need to inform the user that 3 is the maximum. If the user asks to parse 0 sentences, you need to say thank you and exit the program.
Algorithm:
There are many approaches that can be used to complete this algorithm. It is your choice. For example, we have learned that a while loop is a conditional type loop. A for loop is a defined iteration loop.
You can make use of a while loop to cycle through the number of sentences, you could also use a for-loop in this regard; there may be subtle differences in each loop construct and the logic that you need to apply.
Note: that in future chapters we may revisit this solution to enhance and/or change the approach you have used.
At a high level, the approach should be:
- Ask the user to enter the number of sentences to analyze
- Read each sentence in one at a time and assign that sentence to a string variable
- Print out the information as to the number of characters in each input sentence.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started