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 openfilenamew
while True:
name inputEnter a name, or just enter to quit:
if name :
break
file.writename
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 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 fstring 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 copypaste 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
