Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedimage text in transcribed
\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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions