1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Arisa [49]
3 years ago
11

Program:

Computers and Technology
1 answer:
Mkey [24]3 years ago
7 0

Answer:

See explaination

Explanation:

#method to print menu & handle user choice

def print_menu(input_str):

#printing menu

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\n')

#getting choice

choice=input('Choose an option: ').lower()

#identifying choice

if choice=='c':

#displaying number of non white space chars in input_str

print('Number of non-whitespace characters:',get_num_of_non_WS_characters(input_str))

elif choice=='w':

#displaying number of words in input_str

print('Number of words:',get_num_of_words(input_str))

elif choice=='f':

#fixing capitalization and getting updated string and count of values capitalized

input_str,count=fix_capilization(input_str)

#displaying results

print('Number of letters capitalized:',count)

print('Edited text:',input_str)

elif choice=='r':

#replacing punctuation, displaying updated text

input_str=replace_punctuation(input_str)

print('Edited text:', input_str)

elif choice=='s':

#shortening spaces and displaying updated text

input_str = shorten_space(input_str)

print('Edited text:', input_str)

#returning choice and input_str

return choice,input_str

#returns the number of non white space chars in input_str

def get_num_of_non_WS_characters(input_str):

count=0

#looping through each character in input_str

for i in input_str:

if not i.isspace():

#i is not a space

count+=1

return count

#returns the number of words in input_str

def get_num_of_words(input_str):

#splitting words into list of tokens by space

words=input_str.split(' ')

count=0

#counting all non empty strings in words list

for i in words:

if len(i)>0:

count+=1

return count

#method to fix capitalization and return updated string and count of letters updated

def fix_capilization(input_str):

count=0

beginning=True #starting letter should be capitalized

result=''

for i in input_str:

if beginning and i.isalpha():

#start of a sentence and i is alphabetic

if i.islower():

#converting i to upper case, incrementing count

i=i.upper()

count+=1

result+=i

#not start of a sentence

beginning=False

elif i in '?.!':

#i is either ? or . or !, next letter should be capitalized

beginning=True

result+=i

else:

#any other character

result+=i

return result,count

#method to replace exclamation and semicolons with period and comma respectively

def replace_punctuation(input_str,exclamationCount =0,semicolonCount=0):

result=''

for i in input_str:

if i=='!':

i='.'

exclamationCount+=1

elif i==';':

i=','

semicolonCount+=1

result+=i

print('Punctuation replaced')

#displaying replaced values counts

print('exclamationCount:',exclamationCount)

print('semicolonCount:',semicolonCount)

return result

#removes all double or more spaces in input_str

def shorten_space(input_str):

input_str=input_str.strip()

result=''

prev=None

for i in input_str:

if prev==None:

result+=i

elif i==' ':

if prev != ' ':

result+=i

else:

result+=i

prev=i

return result

if __name__ == '__main__':

#getting input, printing it

input_str=input('Enter a sample text:\n')

print('\nYou entered:',input_str)

choice=' '

#looping until choice becomes q

while choice!='q':

choice,input_str=print_menu(input_str)

You might be interested in
You want to copy data from one cell or range to an adjacent cell or range in your spreadsheet, without using a shortcut key. Whi
astraxan [27]

How can you insert a new row into your data without disturbing an adjacent set of data on the same sheet? Highlight only the data where you'd like to insert a row. Right-click > Insert > Shift cells down.

3 0
2 years ago
Which of the following best explains how the Internet is a fault-tolerant system?
IrinaK [193]

Answer:

A

Explanation:

The Internet is fault-tolerant because cybercriminals can conceal their actions, allowing them the ability to carry out faulty actions without leaving a trace.

This statement is actually the same question I had to answer when in my 2nd year 1st semester in itt.
<3 enjoy

8 0
2 years ago
Read 2 more answers
I want to build a video player on the html5 canvas here is my code
jok3333 [9.3K]

Answer:

hospital yestrday after noon ggpupg ki tyutrdcbhsjdvshsjjshsgsgdhsusfsuwwiiwhszia

8 0
1 year ago
A customer dictates instruction on how to transcribe audio. Do you have to transcribe the instruction word for word?
Ostrovityanka [42]

Answer:

No

Explanation:

4 0
2 years ago
You have been given a laptop to use for work. You connect the laptop to your company network, use it from home, and use it while
VashaNatasha [74]
  • You can get a antivirus subscription that will kill malwares
  • Also, you can avoid going on websites you don't trust
  • I hope this helps you.
4 0
3 years ago
Other questions:
  • An electronic resume is a plain-looking document. True of False?
    6·2 answers
  • Define the missing function. licenseNum is created as: (100000 * customID) + licenseYear. Sample output:
    10·2 answers
  • Name types of operating system with example
    5·1 answer
  • Why you should care about copyright
    13·1 answer
  • Guys i really need help pleasure?
    7·2 answers
  • 2. A well designed high-volume system will minimize _________ inventory and reduce _____________for the product or service. a) w
    7·1 answer
  • __________ is a growing practice in cooperative farmingassociations to pool and sell the fruit as a common commodity underthe br
    6·1 answer
  • Alice and Bob decide to communicate using NTRUEncrypt with parameters (N, p, q) = (7, 3, 29). Alice’s public key is h(x) = 3 + 1
    15·1 answer
  • Which option is the correct format of placing HTML tags while coding in HTML?
    13·2 answers
  • Write code that outputs variable numCats. End with a newline.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!