Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function emergency() that takes one parameter, call, which is a string that contains information about a 911 emergency call. Please use python to

image text in transcribed

Write a function emergency() that takes one parameter, call, which is a string that contains information about a 911 emergency call. Please use python to solve the problem.

Write a function emergency() that takes one parameter, call, which is a string that contains information about a 911 emergency call. The function's purpose is to analyze the call (a string) and return a formatted string based on the information. You will need o use the function re.sub thal is discussed in the lecture notes. Only reformal lhe strings thal malch the described paller below. If the sring argumenl call does nol match the pallem, he function should relur invalid format The unformatted string is always in the following format. When a space is shown below, there is exactly one space (meaning they are hard-coded). Fully-capitalized parts like NAME are the parts you need a regular expression to describe. Other non-noted parts (e.g., Hello, my name is) are "hard-coded" and they always stay the same. Pattern to match: Hello, my name is NAME. T need to report EVENT. Please come to WHERE NAME: This part is the caller's name. The name contains two parts exactly (e.g.. "Jane Doe), in which each part starts with an uppercase letter and contains two or more lowercase letters thereafter. EVENT: This part describes the event called in. It may be one word (e-g. "shooting"), or more than one word (e.g. "heart attack", "a very serious collision"). You should handle both lowercase and uppercase letters in the event. WHERE: This part describes the place where the event happened. It has three parts: first it starts with (1) one or more digits that represent the number on the street, then followed by (2) a space, then followed by (3) some leller characters that represent the streel (with possible spaces in between for the streele). Arn example of this is 127 East Main Street'. What Your Function Should Return CSE 101-Fall 2017 Lab 11 Page 4 As mentioned above, your function should take the unformatted string and format it in a specific way like de- scribed below. The all-capitalized parts are the parts you need to move around using re.sub to match the following format: EVENT at WHERE reported by NAME Note: Please follow the format and do not include excessive elements or spaces, since we will be checking the exact string For more information and examples, please look down below. Note that there is only one space between words, which may not be shown correctly in the PDF Example 1 (valid): call 'Hello, my name is Yupeng Yin. I need to report a fire. Please come to 100 Circle Road.' Function Call: emergency (call1) Returned: a fire at 100 circle Road reported by Yupeng Yin' Example 2 (valid): call2 'Hello, my name is Wiktor Laima. I need to report a car accident Please come to 2635 Simons Hollow Road. Function Call: emergency (cal12) Returned: 'a car accident at 2635 Simons Hollow Road reported by Wiktor Laima' Example 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions