Parsing Strings Assessment - email_func program error

Hello,

I am stuck in Python Foundations - Assessments task “Parsing Strings”. When I submit the answer, it throws error as “Function is not returning the appropriate email id”. Please advise what needs to corrected in below program.

def email_func(str1):
position = str1.find(’@’)
first_string = str1[0:position]
second_string = str1[position:]
arr1 = first_string.split()
print(arr1)
arr2 = second_string.split()
print(arr2)
for j in range(0, len(arr1)):
if ‘@’ in arr1[j] and j == 0 and arr1[j].isspace() == False:
email_addr = arr1[j] + arr1[j + 1]
return email_addr
elif ‘@’ in arr1[j] and j > 0 and arr1[j].isspace() == False:
email_addr = arr1[j - 1] + arr2[j]
return email_addr
else:
if len(arr2) >= 1:
for i in range(0, len(arr2)):
if ‘@’ in arr2[i] and i == 0 and arr2[i].isspace() == False:
email_addr = arr1[len(arr1) - 1] + arr2[0]
return email_addr
elif ‘@’ in arr2[i] and i > 0 and arr2[i].isspace() == False:
email_addr = arr2[i - 1] + arr2[i]
return email_addr
else:
return None

Hi, Ayana.

Your code is almost correct!.
But it is not returning None for invalid in the below cases.
str1= “my email is abcd @gmail.com.”
str1= “my email is @gmail.com.”

It is actually clubbing the word before @ and returning it. But it should return None.

All the best!