The Directory.txt file contains names of the employees and their phone numbers in the following order. Last name, First name, Phone. The creator of this file made several mistakes by typing commas and dots inconsistently. Nrite a Python program to read this file and produce an output file with the name DirectoryNew.txt. This file should format the phone directory as follows: Phone First name Number 1 First name 1 Number 2 First name 2 The file MUST end with: End of directory Edit Metadata

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

python 3

The output should be as follows
Phone
First name
2587
Bruce
6958
Amir
5263
Rebecca
5252
John
Mirna
8965
9632
Sundar
1002
Steve
5478
Micheal
8885
Ammar
4696
Jack
9898
Chee
7412
Andrew
6547
Dragos
########## End of directory ##########
1:
Edit Metadata
## This function is used to generate the input file Directory.txt
## Run this cell to gererate the file.
#3
def generateInputFile():
try:
lines=['Springsteen, Bruce, 2587. \n', 'Hassan, Amir, 6958. \n', 'Homes, Rebecca, 5263\n',
"Smith, John, 5252\n', 'MacDonald, Mirna, 8965!\n', 'Pichai, Sundar, 9632. \n',
"Jobs, Steve, 1002\n', 'Goldsmith, Micheal, 5478. \n', 'Yassir, Ammar, 8885\n',
"Nicholas, Jack, 4696\n', 'Pang, Chee, 9898\n', 'Lee, Andrew, 7412.\n',
"Jimenez, Dragos, 6547\n']
outfile = open("Directory.txt",'w')
for line in lines:
outfile.write(line)
except Exception as ex:
print(ex)
finally:
outfile.close()
generateInputFile()
Edit Metadata
#8%writefile HW4Q1.py
## Uncomment the above Line after you finish your code, in order to generate the Python submission file.
# YOUR CODE HERE
Transcribed Image Text:The output should be as follows Phone First name 2587 Bruce 6958 Amir 5263 Rebecca 5252 John Mirna 8965 9632 Sundar 1002 Steve 5478 Micheal 8885 Ammar 4696 Jack 9898 Chee 7412 Andrew 6547 Dragos ########## End of directory ########## 1: Edit Metadata ## This function is used to generate the input file Directory.txt ## Run this cell to gererate the file. #3 def generateInputFile(): try: lines=['Springsteen, Bruce, 2587. \n', 'Hassan, Amir, 6958. \n', 'Homes, Rebecca, 5263\n', "Smith, John, 5252\n', 'MacDonald, Mirna, 8965!\n', 'Pichai, Sundar, 9632. \n', "Jobs, Steve, 1002\n', 'Goldsmith, Micheal, 5478. \n', 'Yassir, Ammar, 8885\n', "Nicholas, Jack, 4696\n', 'Pang, Chee, 9898\n', 'Lee, Andrew, 7412.\n', "Jimenez, Dragos, 6547\n'] outfile = open("Directory.txt",'w') for line in lines: outfile.write(line) except Exception as ex: print(ex) finally: outfile.close() generateInputFile() Edit Metadata #8%writefile HW4Q1.py ## Uncomment the above Line after you finish your code, in order to generate the Python submission file. # YOUR CODE HERE
The Directory.txt file contains names of the employees and their phone numbers in the following order.
Last name, First name, Phone.
The creator of this file made several mistakes by typing commas and dots inconsistently.
Write a Python program to read this file and produce an output file with the name DirectoryNew.txt . This file should format the phone directory as follows:
Phone
First name
Number 1
First name 1
Number 2
First name 2
The file MUST end with:
End of directory
Edit Metadata
Content of the input file
Springsteen, Bruce, 2587.
Hassan, Amir, 6958.
Homes, Rebecca, 5263
Smith, John, 5252
MacDonald, Mirna, 8965!
Pichai, Sundar, 9632.
Jobs, Steve, 1002
Goldsmith, Micheal, 5478.
Yassir, Ammar, 8885
Nicholas, Jack, 4696
Pang, Chee, 9898
Lee, Andrew, 7412.
Jimenez, Dragos, 6547
Transcribed Image Text:The Directory.txt file contains names of the employees and their phone numbers in the following order. Last name, First name, Phone. The creator of this file made several mistakes by typing commas and dots inconsistently. Write a Python program to read this file and produce an output file with the name DirectoryNew.txt . This file should format the phone directory as follows: Phone First name Number 1 First name 1 Number 2 First name 2 The file MUST end with: End of directory Edit Metadata Content of the input file Springsteen, Bruce, 2587. Hassan, Amir, 6958. Homes, Rebecca, 5263 Smith, John, 5252 MacDonald, Mirna, 8965! Pichai, Sundar, 9632. Jobs, Steve, 1002 Goldsmith, Micheal, 5478. Yassir, Ammar, 8885 Nicholas, Jack, 4696 Pang, Chee, 9898 Lee, Andrew, 7412. Jimenez, Dragos, 6547
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT