In: Computer Science
I had a question like this but I forgot to add more and I could not edit it. So here is the new one with more explanation.
I am confused with my Python assignment. I have to write a specification for an email address, Then change the test strings in the code to one string with a valid email address and the other without a valid email address.
This my example/code that it is supposed to be used as a guide:
import re
def text_match(text):
patterns = '^\w+'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
print(text_match("My teacher’s email is [email protected]"))
print(text_match("My teacher has no email address"))
For some reason chegg does not want to indent my lines. the if and else statement should be properly indented in the example
RAW CODE
import re
def text_match(text):
### alphabet or digit + @ + alphabet or digit + . + alphabet or digit or .
patterns = '([a-zA-Z0-9_.]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]+)'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
print(text_match("My teacher’s email is [email protected]"))
print(text_match("My teacher has no email address"))
SCREENSHOTS (CODE AND OUTPUT)
##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####