Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!