Question: # PROBLEM DESCRIPTION: # User enters a sentence and the program counts the # number of characters in it by category: small letters, capital letters,


# PROBLEM DESCRIPTION: # User enters a sentence and the program counts the # number of characters in it by category: small letters, capital letters, # digits, spaces, arithmetic operators (just + - * 1) and other. # # Define a function called "main", and call "main" to start the program. # Define another function "generate_stats" which when called by the "main" # generates the stats. Define another function "print_report" which when # called by the "generate_stats" prints the report. A sample report is shown below. # The sequence of user-defined functions calls is: # main -> generate_stats -> print_report # # Initialize separate variables to store the total of each category. # Use a for loop to iterate through the string to examine each character and # decide which variable to increment. An if/elif/.../else ladder is more efficient # than a stack of if's. # # Hint: # You may use built-in functions like isalpha(), isupper(), # isnumeric(), isspace() in your program. # # SAMPLE REPORT: IIIIII CHARACTER COUNTS FOR THE SENTENCE Category Count a-z 101 A-Z 14 0-9 9 Spaces 24 + - * / 2 Other 11 TOTAL 161 II II II You may use these print statements to print out the report. Change the variable names according to your program. II 11 II print("CHARACTER COUNTS FOR THE SENTENCE Category Count") print("a-z ", lower_letters) print("A-Z upper_letters) print("0-9 numbers) print("Spaces spaces) print("+ - */ special_char) print("Other other_char) print(" --") print("TOTAL total_char) 1 II 1 11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
