Question: In Python: The following program keeps a log of guests checking in to a hotel. It prompts the user for names, writing the responses to

In Python:
The following program keeps a log of guests checking in to a hotel. It prompts the user for names, writing the responses to a new file called, guest.txt.
filename = "guest.txt"
file = open(filename,"w")
while True:
name = input("Enter a name, or just enter to quit: ")
if name =="":
break
file.write(name +'
')
file.close()
After running your program from the previous exercise, your manager says that the guests were supposed to be numbered as they checked in. Rather than track down all the guests, you will use the data you have already gathered.
Write a new program that reads the names from guest.txt and copies them into a new file, numberedGuest.txt. Each line in the new file should contain the line number, a tab, then the name.
Use a for loop to read the file, one line at a time. Refer to an earlier exercise in this lab for an example.
The line number is a counter. Initialize the counter before the loop; increment by 1 inside the loop.
Use the '\t' escape sequence to insert a tab between the line number and the name.
Build each modified line using an f-string or string concatenation. If you choose the latter, you will need to convert the line number to a string using the str() function.
No comments required. You may copy-paste your code into the textbox below, or attach your program file using the Documents button.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!