Hi there, please write code in Python 3 and show what input you used for the...

50.1K

Verified Solution

Question

Programming

Hi there, please write code in Python 3 and show what input youused for the program. I've been stuck on this for hours!

(1) Prompt the user to enter a string of their choosing. Storethe text in a string. Output the string. (1 pt)

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!


(2) Implement a print_menu() function, which has a string as aparameter, outputs a menu of user options for analyzing/editing thestring, and returns the user's entered menu option and the sampletext string (which can be edited inside the print_menu() function).Each option is represented by a single character.

If an invalid character is entered, continue to prompt for avalid choice. Hint: Implement the Quit menu option beforeimplementing other options. Call print_menu() in the mainsection of your code. Continue to call print_menu() until the userenters q to Quit. (3 pts)

Ex:

MENUc - Number of non-whitespace charactersw - Number of wordsf - Fix capitalizationr - Replace punctuations - Shorten spacesq - QuitChoose an option:


(3) Implement the get_num_of_non_WS_characters() function.get_num_of_non_WS_characters() has a string parameter and returnsthe number of characters in the string, excluding all whitespace.Call get_num_of_non_WS_characters() in the print_menu() function.(4 pts)

Ex:

Number of non-whitespace characters: 181


(4) Implement the get_num_of_words() function. get_num_of_words()has a string parameter and returns the number of words in thestring. Hint: Words end when a space is reached except for thelast word in a sentence. Call get_num_of_words() in theprint_menu() function. (3 pts)

Ex:

Number of words: 35


(5) Implement the fix_capitalization() function.fix_capitalization() has a string parameter and returns an updatedstring, where lowercase letters at the beginning of sentences arereplaced with uppercase letters. fix_capitalization() also returnsthe number of letters that have been capitalized. Callfix_capitalization() in the print_menu() function, and then outputthe the edited string followed by the number of letterscapitalized. Hint 1: Look up and use Python functions.islower() and .upper() to complete this task. Hint 2: Create anempty string and use string concatenation to make edits to thestring. (3 pts)

Ex:

Number of letters capitalized: 3Edited 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!


(6) Implement the replace_punctuation() function.replace_punctuation() has a string parameter and two keywordargument parameters exclamation_count andsemicolon_count. replace_punctuation() updates thestring by replacing each exclamation point (!) character with aperiod (.) and each semicolon (;) character with a comma (,).replace_punctuation() also counts the number of times eachcharacter is replaced and outputs those counts. Lastly,replace_punctuation() returns the updated string. Callreplace_punctuation() in the print_menu() function, and then outputthe edited string. (3 pts)

Ex:

Punctuation replacedexclamation_count: 1semicolon_count: 2Edited 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.


(7) Implement the shorten_space() function. shorten_space() has astring parameter and updates the string by replacing all sequencesof 2 or more spaces with a single space. shorten_space() returnsthe string. Call shorten_space() in the print_menu() function, andthen output the edited string. Hint: Look up and use Pythonfunction .isspace(). (3 pt)

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!

Answer & Explanation Solved by verified expert
3.7 Ratings (322 Votes)
SOLUTIONI have solve the problem in python code with comments andscreenshot for easy understanding CODEpython codeimport stringimport reOUT 0IN 1def printmenuuserStrmenuOp printnMENUnc Number of non whitespace Charactersnw Numberof wordsnf fix capatilizationnr Replace punctuationns Shorten spacesnq Quitwhile TruemenuOpinputnChoose an option ifmenuOp in cwfrsqbreakprintif menuOpqreturn menuOpuserStrelifmenuOpcprintNumebr of    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students