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
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
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8e050e4f-e441-4783-8761-d30a19163189%2Fe7167174-59ed-4272-a51c-7437fd4b4132%2Fbmh55pz_processed.jpeg&w=3840&q=75)
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8e050e4f-e441-4783-8761-d30a19163189%2Fe7167174-59ed-4272-a51c-7437fd4b4132%2Fpp9z29_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT