I def find enail(s: str) -> str: Given a string , return the enail thot exists in the string. Preconditions: es> contoins at most 1 email, or none ot oll. If cs> does not contain on enail, return the enpty string. Emoil definition: An enail oddress is defined os 'none@donain.com' or 'nane@donain.co with the folloning specifications: name: the nome is an olphonumeric string that is less than or equol to 12 chorocters. Additionol charocters ollowed ore dosh (-), period (.) and underscore ). But the email connot stort or end with these odditional charocters. The none must olso be ot least 1 charocter Long. Example names: ab 0_b AB..C--D Int3r3st. Ing domain: the domain is strictly nunericol, and the number must be divisible by 5. the Length of the donain is unrestricted. Exomple domains: 984125 ending: the enail must end with a (.com) or (.co) (cose sensitive) Note: you mUst not use ony Loops (for, while) here. We want you to just use the re Library for this function. >> find enail('123450_test_enaila165265365.com!) 'a_test enoil@165265365. com reg = "(la-zA-Z0-]{1}[a-zA-ZB-0.J(1,11})@C[0-91+)[5]L.J(la-zA-Z]+)"

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

Do not add any imports, the ones that you need will be given to you.
Do not use try-except statements, you should be able to anticipate
or prevent any errors from happening at all!

def find enail(s: str) -> str:
Given a string <s>, return the emoil that exists in the string.
Preconditions:
<s> contains at most 1 emoil, or none ot oll.
If cs> does not contain on email, return the empty string.
Email definition:
An emoil oddress is defined os 'nomeadomain.com' or 'nane@domoin.co'
with the following specifications:
name: the nome is on olphanuneric string that is less than or
equol to 12 charocters. Additional charocters ollowed are
dash (-), period (.) and underscore (). But the emoilL
cannot start or end with these odditional characters.
The name must olso be ot least 1 character Long.
Example names:
ob
o_b
A_B..C--D
Int3ršst. Ing
domain: the domain is strictly numericol, and the number must be
divisible by 5. the Length of the domain is unrestricted.
Example donains:
984125
ending: the email must end with a (.com) or (.ca) (cose sensitive)
Note: you mUst not use any Loops (for, while) here.
We want you to just use the re Library for this function.
d_emoil('12345o_test_email@165265365. com!')
'a_test_email@l165265365. com
reg = "([a-zA-ZB-91{1}[a-zA-Z0-9+_.J{1,11})@([0-9]+) [5][.J([a-zA-Z]+)"
m = re.search(reg, s)
if (m == None):
mail =
else:
mail - n.group()
return mail
Transcribed Image Text:def find enail(s: str) -> str: Given a string <s>, return the emoil that exists in the string. Preconditions: <s> contains at most 1 emoil, or none ot oll. If cs> does not contain on email, return the empty string. Email definition: An emoil oddress is defined os 'nomeadomain.com' or 'nane@domoin.co' with the following specifications: name: the nome is on olphanuneric string that is less than or equol to 12 charocters. Additional charocters ollowed are dash (-), period (.) and underscore (). But the emoilL cannot start or end with these odditional characters. The name must olso be ot least 1 character Long. Example names: ob o_b A_B..C--D Int3ršst. Ing domain: the domain is strictly numericol, and the number must be divisible by 5. the Length of the domain is unrestricted. Example donains: 984125 ending: the email must end with a (.com) or (.ca) (cose sensitive) Note: you mUst not use any Loops (for, while) here. We want you to just use the re Library for this function. d_emoil('12345o_test_email@165265365. com!') 'a_test_email@l165265365. com reg = "([a-zA-ZB-91{1}[a-zA-Z0-9+_.J{1,11})@([0-9]+) [5][.J([a-zA-Z]+)" m = re.search(reg, s) if (m == None): mail = else: mail - n.group() return mail
def test_template (f: Callable) -> None:
This is a template for the tests you will write for this lab.
Implement your tests as top level functions that begin with the
word 'test' and take in a callable function <f>.
You are free to do some amount of work to construct your tests cases
within the function but your function must end with an assert statement
of the form <assert f('string') == 'some string'>.
An assert statement means that you expect the boolean expression following
to evaluate to True. With regards to this lab, it means that you expect the
function call on the left to return the string on the right. If this does
not happen, then the assert statement will raise an AssertionError, which
we will catch and take it to mean that this particular test failed.
IMPORTANT:
The goal of this part of the lab is to write a set of tests such that that
ALL of them pass for any correct implementation, but AT LEAST ONE of them
fail for any incorrect implementation (of "find_email").
assert f('test@0.com')
'test@0.com'
==
Transcribed Image Text:def test_template (f: Callable) -> None: This is a template for the tests you will write for this lab. Implement your tests as top level functions that begin with the word 'test' and take in a callable function <f>. You are free to do some amount of work to construct your tests cases within the function but your function must end with an assert statement of the form <assert f('string') == 'some string'>. An assert statement means that you expect the boolean expression following to evaluate to True. With regards to this lab, it means that you expect the function call on the left to return the string on the right. If this does not happen, then the assert statement will raise an AssertionError, which we will catch and take it to mean that this particular test failed. IMPORTANT: The goal of this part of the lab is to write a set of tests such that that ALL of them pass for any correct implementation, but AT LEAST ONE of them fail for any incorrect implementation (of "find_email"). assert f('test@0.com') 'test@0.com' ==
Expert Solution
steps

Step by step

Solved in 5 steps with 2 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
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