Question: This program also tests your ability to analyze and manipulate strings. You have been provided a starter file The starter code will open a file

This program also tests your ability to analyze and manipulate strings.

You have been provided a starter file

The starter code will open a file named strings.txt if it is in the same directory as your Python program. You can create your own stings.txt file or download the one provided on Blackboard. Note that opening and reading files is something you will learn about in Lesson 8. The starter code will read the file line by line, and pass each line to a function called manipulate_text(). You will be filling in the code for this function.

The manipulate_text() function accepts one string as input. The function should do the following with the string parameter:

Strip the leading and trailing whitespace, and output the string.

Determine if the string is all uppercase, all lowercase, or all digits. Print a message that indicates if any of those characteristics is true or don't print anything if none of the characteristics are true.

Print how many of these characters are in the string: X, z, 7

Concatenate the string "<<< Test" to the end of the string and print the new string.

Print how many characters are in the concatenated string.

For example, if this is the contents of strings.txt:

STYLE SHEETS EXAMPLE 777

forest zipzoom 7 times

778992339

This is the last sentence.

This would be the output of your program:

STYLE SHEETS EXAMPLE 777

String is all uppercase.

The line has 1 X's

The line has 0 z's

The line has 3 7's

STYLE SHEETS EXAMPLE 777<<< Test

The string has 32 characters.

forest zipzoom 7 times

String is all lowercase.

The line has 0 X's

The line has 2 z's

The line has 1 7's

forest zipzoom 7 times<<< Test

The string has 30 characters.

778992339

String is all digits.

The line has 0 X's

The line has 0 z's

The line has 2 7's

778992339<<< Test

The string has 17 characters.

This is the last sentence.

The line has 0 X's

The line has 0 z's

The line has 0 7's

This is the last sentence.<<< Test

The string has 34 characters.

 starter code import os # DO NOT CHANGE ANY CODE IN THE MAIN FUNCTION def main(): try: input_file = open('strings.txt', 'r') # Open a file for reading for line in input_file: # Use a for loop to read each line in the file manipulate_text(line) print() except FileNotFoundError: print('Did not find strings.txt in current directory:') print(os.getcwd()) def manipulate_text(line): # Delete the following line, then implement the function as indicated # in the problem specification print(line) 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!