Question: Character Analysis If you have downloaded the source code you will find a file named text.txt. Write a program that reads the file's contents and
Character Analysis
If you have downloaded the source code you will find a file named text.txt. Write a program that reads the file's contents and determines the following:
- The number of uppercase letters in the file.
- the number of lowercase letters in the file.
- the number of digits in the file.
- the number of white space characters in the file.
Please provide comments in code.


\fProgram listing with three lines of code missing: 1 Programming Exercise 2 =def main () : # Local variables num upper = 0 num lower = 0 num space = 0 num digits = 0 data = # Open file text. txt for reading. 10 infile = open ('text. txt', 'r' ) 11 # Read in data from the file. 12 data - infile . read () 13 # Step through each character in the file. 14 # Determine if the character is uppercase, 15 lowercase, a digit, or space, and keep a 16 running total of each. 17 for ?? in ????: 18 8 ?? ?? . ??? ? ??? ( ) : 19 num upper num_upper 20 if ch . islower () : 21 ????????? = ????????? + ? 22 if ch . isdigit () : 23 num digits = num digits + 1 24 if ch . isspace () : 25 num space = num space + 1 26 # Close the file. 27 infile . close () 28 # Display the totals. 29 print ( 'The number of uppercase letters in the file: ', num upper) 30 print ('The number of lowercase letters in the file: ', num lower) 31 print ('The number of digits in the file: ', num digits) 32 print ( 'The number of whitespace in the file: ', num space) 33 Call the main function. 34 main () 35 36 Figure 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
