Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLS Help with code! Write a program named labprep8.py that prompts the user for a filename to evaluate, reads the contents of the file and

PLS Help with code! Write a program named labprep8.py that prompts the user for a filename to evaluate, reads the contents of the file and displays an alphabetical analysis of the number of occurrences of each character contained in the file. Youre provided with several files that you can use to test your Python program. It should work correctly with all of them.

Part 1

#Define a main() function that displays a message describing the purpose of the program

#Prompt the user for the file name containing the text to be processed

PART 2 The readData() function should accept one argument (a filename as a String) and should return two values (a String and a Set). The String returned contains the contents of the text file. The Set returned contains all the characters in the text file with no duplicates.

#Define the readData() function to accept one argument, a String

#Open the text file using the file name String provided as an argument

#Read the contents of the text file into a new String #Close the text file

#Create a Set containing all the unique characters in the String read from the text file

# Return the the text from the file as a String and the Set of unique characters.

Part 3 The calc() function should accept two arguments (a String and a Set) and returns a Dictionary. The String and Set arguments were created by the readData() function and contain the data from the text file and the Set of unique characters. The calc() function creates and returns a Dictionary containing the number of occurrences of each character in the Set

#Define the calc() function that accepts two arguments, a String and a Set

#Create a Dictionary using the entries in the Set as keys and the number of occurrences for each entry in the String as values

#The calc() function should return the new Dictionary

Part 4 Modify the main() function

#Modify the main() function to display the message, 'Reading data file...'

#Modify the main() function to call readData() providing the file name as an argument. (Remember to assign the String and Set returned by readData() to variables)

#Modify the main() function to display the message, 'Analyzing data file...'

#Modify the main() function to call calc() providing the String and Set as arguments (Remember to assign the Dictionary returned by calc() to a variable)

#Modify the main() function to display the message, 'Printing analysis results...'

#Print the key - value pairs from the Dictionary in alphabetical order

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions