Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Python, with the attached text file , write a program that reads the file\'s

ID: 3811958 • Letter: I

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 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()

Explanation / Answer

Hi

I have updated the code and highlighted the code changes below

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 ch in data:
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()

Output:

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

The number of uppercase letters is: 2                                                                                                                                                                                                                                  

The number of lowercase letters is: 10                                                                                                                                                                                                                                 

The number of digits is: 0                                                                                                                                                                                                                                             

The number if whitespace is: 2

text.txt

abcd ee
vgfr@@AA

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote