Small Text Processing System Project

Description

Don't use plagiarized sources. Get Your Custom Essay on
Small Text Processing System Project
Just from $13/Page
Order Essay

We spent time in class discussing the differences between a word processor and simple text editor. This assignment gives you the chance to create a very small text processing system. This is an exercise in following the instructions and in properly structuring your code into the required functions. As usual, I am happy to talk to you in lab or office hours to help you over rough spots.

A novelty of this assignment from others is the use of the line:

if name == “main”:

You must NOT remove that line. And you must define all your functions above that line and place some code below it as this is most likely where your program will begin executing if you follow the instructions carefully. Let me explain why this is important.

When we study modules you will see that the module takes a name once it begin running. If the program was started from the operating system it will have the name “main” but if it was started because it was imported, it will have the name of the file from which it was imported. The Zybook testing system usually does what is called compare output. Your program is run on their system and the output is compared to the expected output for that program. Every difference is noted as you have already seen. So to get a perfect score means have the output be perfect.

This program will have another test. Instead of always testing the entire program, the functions will be called by themselves. So if a function takes a value and is supposed to return another value, Zybook will call your function with its arguments and compare the result returned by your function. So if you PRINT instead of RETURN a value, the appearance may be the same but the program is not correct and the test of that function will fail.

The last point you should know concerns step 4. The main loop for asking for input and looping until there is no more needs to be below the if name … line. The program should stop when the user enters the ‘q’ command so the main loop will be while cmd != ‘q’: or something similar

As they advise, you should code this and make sure your program will terminate when you enter a ‘q’ before you go onto the next step.

(Part 1) Prompt the user to enter some block of text of their choosing. Store the text in a string. Echo that string to the use.

Ex:

Enter a sample text:
and today we will continue our quest in space.  there will be more rockets and more crews and,  absolutely,  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!

You entered: and today we will continue our quest in space.  there will be more rockets and more crews and,  absolutely,  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!

(Part 2) Implement the print_menu() function to print the following command menu.

Ex:

MENU
c - Number of non-whitespace characters
w - Number of words
f - Fix capitalization
r - Replace punctuation
s - Shorten spaces
q - Quit

(Part 3) Stub out the execute_menu() function. It has 2 parameters: a character representing the user’s choice and the user provided sample text. execute_menu() performs the menu options, according to the user’s choice, by calling the appropriate functions described below.

Since this is only a stub, it does not need to do anything for this step. Have it return a null string.

(Part 4) In the main program, (that part of the program after the if __name __ == 'the main") call print_menu() and prompt for the user's choice of menu options for analyzing/editing the string. Each option is represented by a single character.

If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling execute_menu(). That is, call the execute_menu using the option and text as arguments to the function call. Then, print the menu and prompt for a new option. Continue until the user enters ‘q’. Hint: Implement Quit before implementing other options.

Ex:

MENU
c - Number of non-whitespace characters
w - Number of words
f - Fix capitalization
r - Replace punctuation
s - Shorten spaces
q - Quit

Choose an option:

(Part 5) Implement the get_num_of_non_WS_characters() function. This function will accept a string as a parameter and return the number of non-white space characters found in that string. Call the get_num_of_non_WS_characters() in the execute_menu() function. Also in the execute_menu function you must print the message.

Ex:

Enter a sample text:
we'll continue our quest in space.  there will be more shuttle flights and more shuttle crews and,  yes,  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!

You entered: we'll continue our quest in space.  there will be more shuttle flights and more shuttle crews and,  yes,  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!

MENU
c - Number of non-whitespace characters
w - Number of words
f - Fix capitalization
r - Replace punctuation
s - Shorten spaces
q - Quit

Choose an option:
c
Number of non-whitespace characters: 181

(Part 6) Implement the get_num_of_words() function. get_num_of_words() has a string parameter and returns the number of words in the string. Note that there may be multiple spaces between words.

Hint: Words end when a space is reached except for the last word in a sentence.

Call get_num_of_words() in the execute_menu() function, and then output the returned value.

Ex:

MENU
c - Number of non-whitespace characters
w - Number of words
f - Fix capitalization
r - Replace punctuation
s - Shorten spaces
q - Quit

Choose an option:
w
Number of words: 35

(Part 7) Implement the fix_capitalization() function. fix_capitalization() has a string parameter and returns an updated string, where lowercase letters at the beginning of sentences are replaced with uppercase letters. fix_capitalization() also returns the number of letters that have been capitalized. Call fix_capitalization() in the execute_menu() function, and then output the number of letters capitalized followed by the edited string.

Hint 1: Look up and use Python string methods .islower() and .upper() to complete this part.

Hint 2: Create an empty string and use string concatenation to make edits to the string.

Hint 3: Note that this function returns two values. When you call it, you must accept the two values the function returns. (see 6.15) *

Ex:

Number of letters capitalized: 3
Edited text: We'll continue our quest in space.  There will be more shuttle flights and more shuttle crews and,  yes;  more volunteers, more civilians,  more teachers in space.  Nothing ends here;  our hopes and our journeys continue!

(Part 8) Implement the replace_punctuation() function. The replace_punctuation() function has a string parameter and two keyword argument parameters exclamation_count and semicolon_count. The replace_punctuation() function changes the string by replacing each exclamation point (!) character with a period (.) and each semicolon (;) character with a comma (,). The replace_punctuation() function also counts the number of times each character is replaced and outputs those counts. Lastly, replace_punctuation() returns the updated string. Call replace_punctuation() in the execute_menu() function, output the counts, and then output the edited string. Unlike the other functions, the output (printing) is done within this function and not in the execute_menu function.

Hint 1: Note that this has two KEYWORD ARGUMENTS. (see 6.14)
All parameters create a new variable within the namespace of the function and you can treat these as local variables. And that includes altering their value within the function. The apparent thought behind specifying these parameters is that a prior run may have counted some punctuation and so this subroutine should not start with zero. However that use of this function is not motivated in the larger program so you should just assume that you start your counts as zero. Since the intended use is to POTENTIALLY pass in initial values for these two counts, the proper way to initialize them is to either have default values of zero or to explicitly pass in values using the function call. For example if you were to call the function with the assumption that it should start the semicolon count at 33, the call line would look like this: replace_punctuation(text, semicolon =33) Then your function would increment starting at 33 since the passed parameter would override the default.

Ex:

Punctuation replaced
exclamation_count: 1
semicolon_count: 2
Edited text: we'll continue our quest in space.  there will be more shuttle flights and more shuttle crews and,  yes,  more volunteers, more civilians,  more teachers in space.  nothing ends here,  our hopes and our journeys continue.

(Part 9) Implement the shorten_space() function. shorten_space() has a string parameter and updates the string by replacing all sequences of 2 or more spaces with a single space. shorten_space() returns the string. Call shorten_space() in the execute_menu() function, and then output the edited string. Hint: Look up and use Python function .isspace().

Ex:

Edited text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue!

  • MORE HINTS
    The functions that have print statements are printmenu(), executemenu(), replace_punctuation(), and your main routine.
  • >>>
    = RESTART: /Users/fletterd/Google Drive/ECS32A-Winter22/solutions/6.18/main.py
    Enter a sample text:
    and today we will continue our quest in space.  there will be more rockets and more crews and,  absolutely,  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!

    You entered: and today we will continue our quest in space.  there will be more rockets and more crews and,  absolutely,  more volunteers, more civilians,  more teachers in space.  nothing ends here;  our hopes and our journeys continue!

    MENU
    c - Number of non-whitespace characters
    w - Number of words
    f - Fix capitalization
    r - Replace punctuation
    s - Shorten spaces
    q - Quit

    Choose an option:
    c
    Number of non-whitespace characters: 183

    MENU
    c - Number of non-whitespace characters
    w - Number of words
    f - Fix capitalization
    r - Replace punctuation
    s - Shorten spaces
    q - Quit

    Choose an option:
    w
    Number of words: 36

    MENU
    c - Number of non-whitespace characters
    w - Number of words
    f - Fix capitalization
    r - Replace punctuation
    s - Shorten spaces
    q - Quit

    Choose an option:
    f
    Number of letters capitalized: 3
    Edited text: And today we will continue our quest in space.  There will be more rockets and more crews and,  absolutely,  more volunteers, more civilians,  more teachers in space.  Nothing ends here;  our hopes and our journeys continue!

    MENU
    c - Number of non-whitespace characters
    w - Number of words
    f - Fix capitalization
    r - Replace punctuation
    s - Shorten spaces
    q - Quit

    Choose an option:
    r
    Punctuation replaced
    exclamation_count: 1
    semicolon_count: 1
    Edited text: and today we will continue our quest in space.  there will be more rockets and more crews and,  absolutely,  more volunteers, more civilians,  more teachers in space.  nothing ends here,  our hopes and our journeys continue.

    MENU
    c - Number of non-whitespace characters
    w - Number of words
    f - Fix capitalization
    r - Replace punctuation
    s - Shorten spaces
    q - Quit

    Choose an option:
    s
    Edited text: and today we will continue our quest in space. there will be more rockets and more crews and, absolutely, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue!

    MENU
    c - Number of non-whitespace characters
    w - Number of words
    f - Fix capitalization
    r - Replace punctuation
    s - Shorten spaces
    q - Quit

    Choose an option:
    q
    >>> 

Order your essay today and save 20% with the discount code: ESSAYHELP

Order a unique copy of this paper

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
Top Academic Writing Service Ready to Help
with Your Essays, Assignments, and Research

Order your essay today and save 20% with the discount code ESSAYHELP