Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! I would like to know the how and why to the following, please. Must use functions from: https://ecpyfac.ecornell.com/docs/introcs/index.html With this information, complete the function,

Hello!

I would like to know the how and why to the following, please.

Must use functions from: https://ecpyfac.ecornell.com/docs/introcs/index.html

With this information, complete the function, making sure to use an if-else statement. As there are only two possible types of e-mail addresses, it should be pretty straightforward to figure out how to do this.

The harder part is figuring out how to extract the name. This obviously involves string slicing, but you need to know where to slice. There are functions in theintrocsmodule that can help you here.

Extend your implementation ofextract_nameto include the third e-mail address type. You should do this by adding anelifto your if-else statement.

Function:

import introcs

def extract_name(s):

"""

Returns the first name of the person in e-mail address s.

We assume (see the precondition below) that the e-mail address is in one of

three f..t@megacorp.com

last.first.middle@c..t@mompop.net

where first, last, and middle correspond to the person's first, middle, and

last name. Names are not empty, and contain only letters. Everything after the

@ is guaranteed to be exactly as shown.

The function preserves the capitalization of the e-mail a..n@megacorp.com') returns '..y@consultant.biz') returns '..e@mompop.net') returns '..d@mompop.net') returns 'Bob'

Parameter s: The e-mail address to extract from

Precondition: s is in one of the two address formats described above

"""

Current Code:

separate = introcs.split(s,'@')

name = separate[0]

domain = separate[-1]

if domain == 'megacorp.com':

fname = introcs.split(name,'.')[-1]

lname = introcs.split(name,'.')[0]

return fname

elif domain == 'consultant.biz':

middle = introcs.split(name,'.')[-1]

middle1 = introcs.split(name,'.')[0]

mname = introcs.find_str(separate,'', middle, middle1)

return mname

else:

if domain == 'mompop.net':

fname1 = introcs.split(name, '.')[0]

return fname1

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions