Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Python 3) Hi, I need help with the following question. The following code is al

ID: 3571742 • Letter: #

Question

(Python 3) Hi, I need help with the following question.

The following code is already given:

#Type all other functions here

def print_menu(usrStr):
   menuOp = ' '
   #Complete print_menu() function
   return menuOp, usrStr


if __name__ == '__main__':
    #Complete main section of code

7.19 Program: Authoring assistant (Python 3) (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) 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! (2) Implement a print menu( function, which has a string as a parameter, outputs a menu of user options for analyzing/editing the string, and returns the users entered menu option and the sample text string (which can be edited inside the print menu0 function). Each option is represented by a single character lf an invalid character is entered, continue to prompt for a valid choice. Hint lmplementthe Quit menu option before implementing other options. Call print menu 0 in the main section of your code. Continue to call print menu until the user enters q to Quit. (3 pts 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 (3) Implement the get num of non WS characters function. get num of non WS characters has a string parameter and returns the number of characters in the string, excluding all whitespace. Call get num of non WS characters in the print menu function. (4 pts Number of non-whitespace characters 181

Explanation / Answer

Here are the few functions for you:

#!/usr/bin/python
def get_num_of_non_WS_characters(usrStr):
count = 0
for i in range(usrStr):
if usrStr[i] != ' ':
count += 1
return count
def get_num_of_words(usrStr):
count = 0
for i in range(usrStr):
if usrStr[i] == ' ':
count += 1
return count + 1
def fix_capitalization(usrStr):
count = 0
if usrStr[0].islower():
usrStr[0] = usrStr[0].upper()
count += 1
for i in range(usrStr):
if usrStr[i] == '.':
if usrStr[i+2].islower():
usrStr[i+2] = usrStr[i+2].upper()
count += 1
return usrStr, count   
def print_menu(usrStr):
menuOp = ' '
print 'MENU'
print 'c - Number of non-whitespace characters'
print 'w - Number of words'
print 'f - Fix capitalization'
print 'r - Replace punctuation'
print 's - Shorten spaces'
print 'q - Quit'
menuOp = input('Choose an option: ')
if menuOp == 'c':
print 'Number of non-whitespace characters: ', get_num_of_non_WS_characters(usrStr)
elif menuOp == 'w':
print 'Number of words: ', get_num_of_words(usrStr)
elif menuOp == 'f':
usrStr, count = fix_capitalization(usrStr)
print 'Number of letters capitalized: ', count
elif menuOp == 'r':
print 'To be implemented'
elif menuOp == 's':
print 'To be implemented'
elif menuOp == 'q':
return menuOp, usrStr
else:
print_menu(usrStr)