Question
In python just using if-else can anyone help me to implement function of thi def extract_name(s): Returns the first name of the person in
In python just using if-else can anyone help me to implement function of thi 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 two forms: last.first@megacorp.com first.last@mompop.net where first and last correspond to the person's first 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 address. Examples: extract_name('smith.john@megacorp.com') returns 'john' extract_name('maggie.white@mompop.net') returns 'maggie' extract_name('Bob.Bird@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 """ Right now I have
x =introcs.split(s, ('@'),[0]) y =introcs.split(s, ('@'),[1])
if y =='megacorp.com': a = introcs.split(x, ('.'),[1]) else: a = introcs.split(x, ('.'),[0]) return a But getting this error
The call extract_name('smith.john@megacorp.com') crashed. Traceback (most recent call last): TypeError: 'list' object cannot be interpreted as an integer
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started