Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The alphabets.py file contains: def remove_nonalphabet(msg): # Complete the remove_nonalphabet function. # Don't forget comment the code per the coding convention # new string new

image text in transcribed

The alphabets.py file contains:

def remove_nonalphabet(msg): # Complete the remove_nonalphabet function. # Don't forget comment the code per the coding convention # new string new = "" # for loop if character is in msg for i in msg: # checks if letter is alphabetic or not if i.isalpha(): # if alphabetic it gets added to new new += i # return final output return new

# complete this program. if __name__ == "__main__": # input sentence = input("Enter a message: ") # output print(remove_nonalphabet(sentence))

The message.txt contains:

One fish, Two fish, Red fish, Blue fish, Black fish, Blue fish, Old fish, New fish. This one has a little car. This one has a little star. Say! What a lot of fish there are. Yes. Some are red, and some are blue.

----------------------------------------------------------

And the original code written in the photo is:

def word_frequencies(file_obj):

# Implement the word_frequencies function. The file_obj function parameter is a file object.

# Don't forget comment the code per the coding convention # The main program. Do not change it.

if __name__ == '__main__': filename = input("Enter a filename: ") file_object = open(filename, "r") your_dictionary = word_frequencies(file_object) sorted_keys = sorted(your_dictionary.keys()) for key in sorted_keys: print(key + ': ' + str(your_dictionary[key])) file_object.close()

Write a program that prompts user to enter a filename. It read the file and prints a table of word frequencies. The words are in alphabetical order with the number of times each word occurs. The words are case insensitive. The words may have punctuation marks or other nonalphabetic characters. Use the remove_nonalphabet() function found in week 2 lab to remove any non-alphabetic characters before checking for the word frequencies. def word_frequencies (file_obj): \# Implement the word_frequencies function. The file_obj function parameter is a file object. \# Don't forget comment the code per the coding convention \# The main program. Do not change it. if name_= '_main_': filename = input ("Enter a filename: ") file_object = open(filename, "r") your_dictionary = word_frequencies(file_object) sorted_keys = sorted(your_dictionary.keys()) for key in sorted_keys: print(key ': ' + str(your_dictionary[key])) file_object.close() Use the sample message.txt file to test your program. Note, the message.txt file is downloaded as zip file. Unzip it. Put it in the same directory where you write the program in EdStem workspace environment. Note: You must name the Python file file_word_frequencies.py. No other name will be accepted. Note: The program must import the alphabets.py file and use the remove_nonalphabet ( ) function found in the alphabets.py file. Do no write the remove_nonalphabet () function in the working file. The alphabets.py file is part of week 2 lab

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

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago