Question

WRITE IN PYTHON Using any large text file or any literature English book in .txt format....

WRITE IN PYTHON Using any large text file or any literature English book in .txt format. The program will read a .txt file and process the information

Write a module called, “book_digest”. The module must have the following functions:

● digest_book(file_path: str) -> None ○ This function collects and stores the required information into global dictionaries, lists, and variables. The file (book) is read and parsed only one time then closed ○ This function should raise a FileNotFoundError exception if the file doesn’t exist ○ It would be helpful to create helper functions for this process.

● character_freq() -> dict ○ This function returns the frequency with which alphabet characters are used in the book. Alphabet characters are a-z or A-Z. ○ It returns a dictionary that uses the alphabet character as the key and the number of times it was seen as the value. ○ The alphabet characters should be counted case insensitively. This means that there is only one key for the letter ‘a’ which holds the count of both uppercase ‘a’s and lowercase ‘a’s. ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● word_lengths() -> dict ○ This function returns a dictionary that uses the word length as the key and the number of words of that length as the value. ○ Contractions like, “can’t”, “shouldn’t”, etc., are to be counted as single words and their character count should include the apostrophe. The same goes for abbreviations and their ending period. ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● avg_word_length() -> float ○ This function returns the average word length ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● line_count() -> int ○ This function returns the number of lines in the book ○ A line contains all of the characters separated by a new line character ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● sentence_count() -> int ○ This function returns the number of sentences found in the book ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● unique_word_count() -> int ○ This function returns the number of unique words found in the book ○ See unique_words description for what constitutes a unique word ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● unique_words() -> set ○ This function returns a list of all of the unique words found ○ A unique word can include contractions, abbreviations, and other forms of words. ○ In the case of abbreviations, if the abbreviation is followed by a period then the period should be considered part of the word ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● generate_password(word_qty: int, min_word_len: int, inject_punct: bool) -> str
○ This function returns a password made up of word_qty unique words ○ Each word must be at least min_word_len characters long
○ The user can choose to have a random punctuation character inserted between the words. ■ If this option is not chosen then the words are separated by a space ○ The last two parameters should have a default value set. ■ For min_word_len the default value is 4 ■ For inject_punct the default value is False ○ This function can be called providing the arguments for some or all parameters ○ The argument for word_qty must always be provided. ○ This function should raise an exception called BookNotDigestedError if a book hasn’t first been digested

● A BookNotDigestedError exception which is derived from the Exception class. BookNotDigestedError must be defined in the same module.

Homework Answers

Answer #1

Files is composed of three parts:

  1. Header
  2. End of File(EOF)
  3. Data

File Paths

File path is required to access file in an Operating System.It is the location of the file.

It consists of three parts:

  1. Folder Path
  2. File Name
  3. Extension

Opening and closing a file

reader=open('Box.txt')

try:

#processing

finally:

reader.close()

Note:

  • read(Size=-1) :If this is passed then the whole file is read.
  • readLine(Size=-1):Entire line is read.
  • readlines():reads the remaining lines from the file object.

Iteration in file

with open('Box.txt','r')as reader

line=reader.readline()

while line!=' ' :

print(line,end=' ')

line=reader.readline()

  • digest_book=open('book_digest.txt')
  • reader=open('book_digest.txt')
  • try:
  • FileNotFoundError
  • finally:
  • reader.close()
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Write a program in python that reads in the file quiztext (txt) and creates a list...
Write a program in python that reads in the file quiztext (txt) and creates a list of each unique word used in the file, then prints the list. Generate a report that lists each individual word followed by the number of times it appears in the text, for example: Frequency_list = [('was', 3), ('bird',5), ('it', 27)….] and so on. Note: Notice the structure: a list of tuples. If you're really feeling daring, Google how to sort this new list based...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question....
#Linked Lists and Classes #C++ Hi, please use singly linked list method to do this question. Thank you! Here’s the contents of a file called example.cpp: // example.cpp #include "LinkedList.h" #include <iostream> #include <string> using namespace std; int main() { cout << "Please enter some words (ctrl-d to stop):\n"; LinkedList lst; int count = 0; string s; while (cin >> s) { count++; lst.add(remove_non_letters(s)); } // while cout << "\n" << count << " total words read in\n"; cout <<...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT