def print_menu(usr_str: str): aamenu_options = ['c', 'w', 'f', 'r', 's', 'q'] print('\nMENU') 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\n') aachoice = input('Choose an option: ').lower() while aachoice not in aamenu_options: print('Invalid choice') aachoice = input('Choose an option:') if aachoice == 'c': print('Number of non-whitespace characters:', get_num_of_non_WS_characters(usr_str)) elif aachoice == 'w': print('Number of words:', get_num_of_words(usr_str)) elif aachoice == 'f': usr, count = fix_capitalization(usr_str) print('Number of letters capitalized:', count) print('Edited text:', usr_str) elif aachoice == 'r': usr_str = replace_punctuation(usr_str) print('Edited text:', usr_str) elif aachoice == 's': usr_str = shorten_space(usr_str) print('Edited text:', usr_str) return aachoice, usr_str def get_num_of_non_WS_characters(usr_str:str): count = 0 for i in usr_str: if not i.isspace(): count +=1 return count def get_num_of_words(usr_str: str): num_words = len(usr_str.split()) return num_words def fix_capitalization(usr_str): count = 0 edited_str = '' phrase = s.split('. ') for i in phrase: if i[0].islower(): count +=1 edited_str += i[0].upper() + i[1:] + '. ' else: edited_str += i + '. ' print('Number of letters capitalized:', caps) return count def replace_punctuation(usr_str: str, **kwargs): exclamation_count = 0 semicolon_count = 0 result = '' for i in usr_str: if i == '!': i = '.' exclamation_count += 1 elif i == ';': i = ',' semicolon_count += 1 result += i print('Punctuation replaced', exclamation_count) print('Exclamation Count:', semicolon_count) return result def shorten_space(usr_str:str): result = '' for i in range(len(usr_str) - 1): if not (usr_str[i].isspace() and usr_str[i + 1].isspace()): result += usr_str[i] return result def main(): usr_str = input('Enter a sample text: \n') print('\nYou entered:', usr_str) choice = '' while choice != 'q': choice, usr_str = print_menu(usr_str) if __name__ == '__main__': main() used input in the problem: 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! problem: my fix capitalization has a small problem that is shown in the photo Thank you so much and have a great day.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python code:

Code I have so far:

def print_menu(usr_str: str):
    aamenu_options = ['c', 'w', 'f', 'r', 's', 'q']
    print('\nMENU')
    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\n')

    aachoice = input('Choose an option: ').lower()
    while aachoice not in aamenu_options:
        print('Invalid choice')
        aachoice = input('Choose an option:')
    if aachoice == 'c':
        print('Number of non-whitespace characters:', get_num_of_non_WS_characters(usr_str))
    elif aachoice == 'w':
        print('Number of words:', get_num_of_words(usr_str))
    elif aachoice == 'f':
        usr, count = fix_capitalization(usr_str)
        print('Number of letters capitalized:', count)
        print('Edited text:', usr_str)
    elif aachoice == 'r':
        usr_str = replace_punctuation(usr_str)
        print('Edited text:', usr_str)
    elif aachoice == 's':
        usr_str = shorten_space(usr_str)
        print('Edited text:', usr_str)
    return aachoice, usr_str


def get_num_of_non_WS_characters(usr_str:str):
    count = 0
    for i in usr_str:
        if not i.isspace():
            count +=1
    return count

def get_num_of_words(usr_str: str):
    num_words = len(usr_str.split())
    return num_words
def fix_capitalization(usr_str):
    count = 0
    edited_str = ''
    phrase = s.split('.  ')
    for i in phrase:
        if i[0].islower():
            count +=1
            edited_str += i[0].upper() + i[1:] + '. '
        else:
            edited_str += i + '. '
    print('Number of letters capitalized:', caps)
    return count
    
def replace_punctuation(usr_str: str, **kwargs):
    exclamation_count = 0
    semicolon_count = 0
    result = ''
    for i in usr_str:
        if i == '!':
            i = '.'
            exclamation_count += 1
        elif i == ';':
            i = ','
            semicolon_count += 1
        result += i
    print('Punctuation replaced', exclamation_count)
    print('Exclamation Count:', semicolon_count)
    return result

def shorten_space(usr_str:str):
    result = ''
    for i in range(len(usr_str) - 1):
        if not (usr_str[i].isspace() and usr_str[i + 1].isspace()):
            result += usr_str[i]
    return result
    
def main():
    usr_str = input('Enter a sample text: \n')
    print('\nYou entered:', usr_str)
    choice = ''
    while choice != 'q':
        choice, usr_str = print_menu(usr_str)

if __name__ == '__main__':
    main()

used input in the problem:

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! 

problem:

my fix capitalization has a small problem that is shown in the photo

 

Thank you so much and have a great day.

Python 3.10.6 (tags/v3.10.6:9c7b4bd,
AMD64)] on win32
Type "help", "copyright", "credits" or "license ()" for more information.
= RESTART: C:\Users\lione\OneDrive\Desktop\Final
FirstName-Final Project2.py
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 spa
ce. nothing ends here; our hopes and our journeys continue!
Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (
You entered: we'll continue our quest in space. there will be more shuttle flig
hts and more shuttle crews and, yes; more volunteers, more civilians, more te
achers in space. nothing ends here; our hopes and our journeys continue!
MENU
с - Number of non-whitespace characters
Number of words
W-
f - Fix capitalization
I - Replace punctuation
S
Shorten spaces
q - Quit
Projects StartingFiles\LastName_
phrases.split('.
NameError: name 's' is not defined
Choose an option: f
Traceback (most recent call last):
File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi
rstName-Final Project2.py", line 95, in <module>
main ()
File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi
rstName-Final Project2.py", line 92, in main
choice, usr_str = print_menu (usr_str)
File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi
rstName-Final Project2.py", line 29, in print_menu
usr, count = fix_capitalization (usr_str)
File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi
rstName-Final Project2.py", line 54, in fix_capitalization
Transcribed Image Text:Python 3.10.6 (tags/v3.10.6:9c7b4bd, AMD64)] on win32 Type "help", "copyright", "credits" or "license ()" for more information. = RESTART: C:\Users\lione\OneDrive\Desktop\Final FirstName-Final Project2.py 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 spa ce. nothing ends here; our hopes and our journeys continue! Aug 1 2022, 21:53:49) [MSC v.1932 64 bit ( You entered: we'll continue our quest in space. there will be more shuttle flig hts and more shuttle crews and, yes; more volunteers, more civilians, more te achers in space. nothing ends here; our hopes and our journeys continue! MENU с - Number of non-whitespace characters Number of words W- f - Fix capitalization I - Replace punctuation S Shorten spaces q - Quit Projects StartingFiles\LastName_ phrases.split('. NameError: name 's' is not defined Choose an option: f Traceback (most recent call last): File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi rstName-Final Project2.py", line 95, in <module> main () File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi rstName-Final Project2.py", line 92, in main choice, usr_str = print_menu (usr_str) File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi rstName-Final Project2.py", line 29, in print_menu usr, count = fix_capitalization (usr_str) File "C:\Users\lione\OneDrive\Desktop\Final Projects StartingFiles\LastName_ Fi rstName-Final Project2.py", line 54, in fix_capitalization
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education