Question

please type code in Python find all the VALID email address in this input text file...

please type code in Python

find all the VALID email address in this input text file and store them as a single column of valid email addresses in an output text file labeled OutputFile

First cut/paste the block of text below into a separate text file and label that data file InputFile:

FinancialAid Email: finaid@myschool.edu
Scholarships Financial Aid Phone: 979-555-3236
Email: random@ubx.net Financial visit@tamu.com Aid
helpdesk@tamu.notvalid Help Desk Central
fakename@egr.msu.org Dean's Office     
Jill Educational Program Coordinator II   


Create a program will find all the email address in InputFile and put into an output data file that you will label as OutputFile
Hint: use the character "@" as a cue to help find all the potential email addresses and then
see if you see an ".edu" or a ".net" or a...etc

You will want to check for valid email addresses ie ending in a valid extension. If you find the @ but when you test the rest of the candidate email, you don't see a valid extension simply flag it as an "ERROR" as shown in the output you should get:

scholarships@myschool.edu
financialaid@myschool.net
visit@tamu.com
ERROR=helpuodesk@tamu.notvalid
fakename@egr.msu.org

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

f = open('inputFile.txt')
fo = open("outputFile.txt", "w")
line = f.readline()
while line:
extension=["edu","net","org","com","msv"]
lines=line.split(" ")
for word in lines:
if '@' in word:
dot=word.find(".")
if(dot>0):
ext=word[dot+1:]
while(True):
dot=ext.find(".")
if(dot>0):
ext=ext[dot+1:]
else:
break
ext=ext.rstrip()
if ext in extension:
word=word.rstrip()
fo.write(word+"\n")
else:
fo.write("Error"+word+"\n")
else:
fo.write("Error "+word+"\n")
line = f.readline()
f.close()
fo.close()

inputFile.txt

outputFile.txt

codeSnaps

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Answer #2

One possible solution would be to use regular expressions to search for patterns that match email addresses. Here is an example of how to do this using Python:

pythonCopy codeimport re# Open the input file and read its contentswith open('InputFile.txt', 'r') as f:
    input_text = f.read()# Define a regular expression pattern to match email addressespattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'# Find all the matches in the input textmatches = re.findall(pattern, input_text)# Filter out any invalid email addressesvalid_emails = [email for email in matches if email.endswith(('.com', '.edu', '.net', '.org'))]# Write the valid email addresses to the output filewith open('OutputFile.txt', 'w') as f:
    f.write('\n'.join(valid_emails))

This code reads the input file into a string, defines a regular expression pattern to match email addresses, and uses the re.findall() function to find all the matches in the input text. It then filters out any invalid email addresses by checking that the email address ends with a valid extension (.com, .edu, .net, or .org). Finally, it writes the valid email addresses to the output file.


answered by: Hydra Master
Add a comment
Know the answer?
Add Answer to:
please type code in Python find all the VALID email address in this input text file...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java2 Screenshot of the output required Put some comment This is the mailing text file for...

    Java2 Screenshot of the output required Put some comment This is the mailing text file for the assignment ..Il AT&T令 12:28 AM Back Complete and Submit Lab 2C Detail Submission Grade Complete and Submit Lab 2C Due: Mar 1, 2019 at 11:59 PM In class you learned how to read text from a file using the Scanner class and write text to a file using the Formatter class. This lab allows you to apply the skills you learned about files...

  • Lab 1.4: Arrays, File I/O and Method Review (40 pts) Assume you work for a company...

    Lab 1.4: Arrays, File I/O and Method Review (40 pts) Assume you work for a company that received a list of email addresses of potential new customers from a data broker. Your company receives a file named customers.txt with the below information: Jiming Wu jwu@G.com James Brown Jaime.Boy.Brown@hotmail.com Leanna Perez LeaPerez@att.net Xing Li Xing.Li@sbcglobal.net Stacey Cahill SCahill@G.com Mohammed Abbas downtown_Abbas@yahoo.com Kumari Chakrabarti KukuChakrabarti@att.net Shakil Smith Shakattaq2G.com Jung Ahrin Jung_Ahrin@sbcglobal.net Pedro Martinez Pedro2018@sbcglobal.net Ally Gu I_am_Ally@comcast.com Tamara White Tamtastic@att.net Alvin Ngo...

  • URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to...

    URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to download the uncompressed latest version of jQuery Copy the jQuery.x.x.x.js file in the folder and specified as source file. Task 2: Download and install HTML-Kit 1. Navigate to htmlkit.com. 2. Click Download HTML-Kit 292. After it downloads, launch HKSetup.exe. Choose Full installation (the default) Uncheck Yes, download and install HTML-Kit Tools Trial. 6. Click Next>Finish. Task 3: Creating a Simple jQuery Application Launch HTML-Kit....

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT