Question
In Python, with the attached text file , write a program that reads the file's contents and determines the following: The number of uppercase letters
In Python, with the attached text file , 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 dgits in the file
The number of white space characters in the file
The text reads:
n the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look. You can easily change the formatting of selected text in the document text by choosing a look for the selected text from the Quick Styles gallery on the Home tab. You can also format text directly by using the other controls on the Home tab. Most controls offer a choice of using the look from the current theme or using a format that you specify directly. 123456789 To change the overall look of your document, choose new Theme elements on the Page Layout tab. To change the looks available in the Quick Style gallery, use the Change Current Quick Style Set command. Both the Themes gallery and the Quick Styles gallery provide reset commands so that you can always restore the look of your document to the original contained in your current template.
Here is what I have so far:
def main(): #local variables num_upper = 0 num_lower = 0 num_space = 0 num_digits = 0 data = '' #open file text.txt for reading infile = open('text.txt', 'r') # read in data from the file data = infile.read() # Step through each character in the file #Determine if the character is uppercase #lowercase, a digit or space and keep a #running total of each for _____ in _______:<------ not sure what should go here ... maybe for lines in file? if ch.isupper(): num_upper = num_upper + 1 if ch.islower(): num_lower = num_lower + 1 if ch.isdigit(): num_digits = num_digits + 1 if ch.isspace(): num_space = num_space + 1 #Close the file infile.close() #Display the totals print('The number of uppercase letters is:', num_upper) print('The number of lowercase letters is:', num_lower) print('The number of digits is:', num_digits) print('The number if whitespace is:', num_space) # call the main function main()
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