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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education