Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Please write a python code with 7 different functions in this template

def main():
"""Driver function: calls other functions to perform all tasks."""
lines = get_user_input()
num_words = get_num_words(lines)
num_sentences = get_num_sentences(lines)
avg_words = get_avg_words(num_words, num_sentences)
most_freq_word = get_most_used_word(lines)
print_stats(num_words, num_sentences, avg_words, most_freq_word)
if __name__ == '__main__':
main()

 

o get_user_input() → list : Prompts the user for some text input, which can
include newlines (examples in week 5 lecture notes e). If interactive methods
do not work for you because the OS is using the usual key shortcuts for
something else, please see the screencasts explaining how to use a file
instead (while still accepting interactive input on systems that support it):
Coding Rooms screencast or PyCharm screencast.
o get_num_words(text_lines: list) → int : Returns the number of words; you
can assume words do not span multiple lines and are separated by
whitespace.
o get_num_sentences(text_lines: list) -> float : Returns the number of
sentences. You can assume that a sentence ends with one of the following
punctuation chars: ., ? or 9. You may not assume that a sentence is on a
single line.
o get_avg_words(num_words: int, num_sentences: int) -> float : Returns the
average sentence length rounded to one digit after the decimal point (e.g.,
4.3, but not 4.31).
o get_most_used_word(text_lines: list) -> str : Returns the most frequently
used word (case-insensitive). For ties, the word occurring first is chosen.
o print_stats(num_words: int, num_sentences: int, sent_avg_words: float,
most_freq_word: str): Print all results (number of words, number of
sentences, average sentence length) in a formatted table that is exactly 40
characters wide, see examples.
o The main() function should call other functions to perform all the required
work - no actual text processing, computation, formatting, or printing should
be done in main. This function is already provided for you in the template.
expand button
Transcribed Image Text:o get_user_input() → list : Prompts the user for some text input, which can include newlines (examples in week 5 lecture notes e). If interactive methods do not work for you because the OS is using the usual key shortcuts for something else, please see the screencasts explaining how to use a file instead (while still accepting interactive input on systems that support it): Coding Rooms screencast or PyCharm screencast. o get_num_words(text_lines: list) → int : Returns the number of words; you can assume words do not span multiple lines and are separated by whitespace. o get_num_sentences(text_lines: list) -> float : Returns the number of sentences. You can assume that a sentence ends with one of the following punctuation chars: ., ? or 9. You may not assume that a sentence is on a single line. o get_avg_words(num_words: int, num_sentences: int) -> float : Returns the average sentence length rounded to one digit after the decimal point (e.g., 4.3, but not 4.31). o get_most_used_word(text_lines: list) -> str : Returns the most frequently used word (case-insensitive). For ties, the word occurring first is chosen. o print_stats(num_words: int, num_sentences: int, sent_avg_words: float, most_freq_word: str): Print all results (number of words, number of sentences, average sentence length) in a formatted table that is exactly 40 characters wide, see examples. o The main() function should call other functions to perform all the required work - no actual text processing, computation, formatting, or printing should be done in main. This function is already provided for you in the template.
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY