Create an order summary matriz.

In this assignment you will be processing sentences. For each sentence, you will print out detected references to times and phone numbers. Furthermore, you will be creating a password string from each sentence using a defined algorithm, and assessing its strength. The details are described below.

First, you must define and use the following functions:

1. isPhone() - must be passed a string parameter and should return True if and only if the string looks like a phone number expressed in ddd-ddd-dddd or (ddd)ddd-dddd format, where d is a single digit. Example: '123-345-5555' and '(888) 623-3838" are phones, but 'Greenland' is not.

2. isTime() - must be passed a string parameter and should return True if and only if the string looks like a 24-hour based time value, expressed in 'hh:mm' or "h:mm' format, where hh and mm are appropriate values of hour and minute. For example, 18:34' or '8:30' are time values, while '13:60' or 'abc' are not.

3. parseSentence() - must be passed a string parameter, let's call it sentence. The function must print out all references to times and phone numbers as they appear in the sentence.

Hint: split the sentence into words and run a loop for each word, calling previous two functions on each word.

The function must return two values: a count of how many references to times there were and how many references to phone numbers. For example, when passed the following sentence:

'You can reach us between 10:00 and 12:30 at the following phone number: 781-374-3748'

The function should print

time 10:00
time 12:30
phone 781-374-3748

and return a pair of values (2, 1)

4. passwordFromSentence() - must be passed a string parameter, let's call it sentence. The function must compose a password from the sentence using the following algorithm. The password must include every first letter of each word (word is a sequence of non-blank characters) and every non-alphanumeric value that is not a space. Furthermore, if the password composed this way is longer than 12 characters, cut it to the first 12 characters. For example, given sentence

'In 2009, Mr. Murdoch threatened to remove News Corp articles from Google, accusing the internet giant of stealing its content.'

the returned password should be '12,M.MttNCa'

For 'Out, out brief candle!" The function should return "O, obc!"

Hint: To compose the password, traverse the sentence character by character, always keeping track of the previous character to check if you are in the beginning of a word.

5. passwordStrength() - must be passed a string parameter, let's call it word. The function must return a score: from 0 to 4. Score 0 indicates that the length of the word is less than 8. If the length of the word is 8 or higher, 1 is added to the score for each of the four conditions, if it is satisfied:

  • word has at least one lowercase letter
  • word has at least one uppercase letter
  • word has at least one digit
  • word has a character that is neither a letter nor a digit

Hint: the easiest way to calculate the score involves going through individual characters of the word. If you have an integer value 0 or 1 indicating for each of the required component, if it appears in the word, then the sum of these integers will equal the password strength score.

6. main() function without parameters, should run by asking the user to enter sentences, until user enters nothing. For each sentence, call functions defined above to display references to time, phone numbers, a count of each, compose a password and display its strength as shown below. In the end, print out how many of the generated passwords have strength score 4. The execution is shown in the interaction below.

There should be no code outside of function definitions, except for the call to function main. The following interaction demonstrates how the whole program should run. Boldface denotes user input:

Enter sentence: You can reach us between 18:00 and 12:30 at the following phone number: 781-374-3748
time 10:00
time 12:30
phone 781-374-3748
parseSentence() returned (2, 1)
Password: Ycrub1:al:at strength = 4

Enter sentence: In 2009, Mr. Murdoch threatened to remove News Corp articles from Google, accusing the internet giant of stealing its content.
parseSentence() returned (0, 0)
Password: 12,M.MttrNCa strength = 4

Enter sentence: Shall I compare thee to a summer's day?
parseSentence() returned (0, 0)
Password: SIcttas'd? strength = 3

Enter sentence: Please call us at (345) 586-4576 at your earliest convenince. phone (345)586-4576
parseSentence() returned (0, 1)
Password: Pcua()5-ayec. strength = 3

Enter sentence:
Generated 3 passwords of strength 4
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.