A hotel keeps records of its sales in a text file (called "hotel.txt"; provided in the MOODLE). Each line contains the following information separated by semicolons (":"): The client's name, the service sold (such as Dining, conference...), and the amount of the sale. Figure 2 shows a few lines of input file. Write a program that reads such a file and displays the total and average amount for each service category. Knowing that there are four services (Dining, Lodging, Conference, and Parking). Display an error using the proper exception if: • The file does not open/exist • The format of the data in the file is incorrect (e.g. sale amount = "230;9" or "12ab") • Dividing by zero (when computing average) • Make sure you close any open files even if an error occurs. Benjamin Bayer:Dining:26.5 English Joyce A:Lodging:120.14 Zalaya:Lodging:173.6 Chung-cha kim:Conference:425 Service Total Average Dining Lodging Conference 425.0 425.00 220.8 44.16 544.0 181.35 Dividing by Zero, this hotel service not used Figure 2a input file sample exe2 Figure 2b Output sample exe2

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Use loop to solve this python program 

A hotel keeps records of its sales in a text file (called "hotel.txt"; provided in the MOODLE).
Each line contains the following information separated by semicolons (“:"): The client's name,
the service sold (such as Dining, conference...), and the amount of the sale. Figure 2 shows a
few lines of input file. Write a program that reads such a file and displays the total and average
amount for each service category. Knowing that there are four services (Dining, Lodging,
Conference, and Parking). Display an error using the proper exception if:
The file does not open/exist
The format of the data in the file is incorrect (e.g. sale amount = "230;9" or "12ab")
Dividing by zero (when computing average)
Make sure you close any open files even if an error occurs.
Benjamin Bayer:Dining:26.5
English Joyce A:Lodging:120.14
Zalaya:Lodging:173.6
Chung-cha kim:Conference:425
Service
Total Average
Dining
Lodging
220.8
44.16
544.0 181,35
Conference 425.0 425.00
Dividing by Zero, this hotel service not used
Figure 2a input file sample exe2
Figure 2b Output sample exe2
Optional:
Try to resolve the division by zero error so the output becomes as shown in figure 2c
*****
*****
Service
Total Average
Dining
Lodging
Conference 425.0 425.00
Parking
220.8
44.16
544.0 181.35
0.0
0,00
Figure 2e Output Sample2 exe2
Benjamin Bayer:Dining:26.5
English Joyce A:Lodging:120.14
Zalaya:Lodging:173.6
Chung-cha kim:Conference:425
Davidson:Dining:15.6
Rohan Panchal:Dining:36.9
Barbara Benson:Dining:45.8
Smith John B:Lodging:250.3
Wong, Fanklin:Dining:96
(Hotel text file )
Transcribed Image Text:A hotel keeps records of its sales in a text file (called "hotel.txt"; provided in the MOODLE). Each line contains the following information separated by semicolons (“:"): The client's name, the service sold (such as Dining, conference...), and the amount of the sale. Figure 2 shows a few lines of input file. Write a program that reads such a file and displays the total and average amount for each service category. Knowing that there are four services (Dining, Lodging, Conference, and Parking). Display an error using the proper exception if: The file does not open/exist The format of the data in the file is incorrect (e.g. sale amount = "230;9" or "12ab") Dividing by zero (when computing average) Make sure you close any open files even if an error occurs. Benjamin Bayer:Dining:26.5 English Joyce A:Lodging:120.14 Zalaya:Lodging:173.6 Chung-cha kim:Conference:425 Service Total Average Dining Lodging 220.8 44.16 544.0 181,35 Conference 425.0 425.00 Dividing by Zero, this hotel service not used Figure 2a input file sample exe2 Figure 2b Output sample exe2 Optional: Try to resolve the division by zero error so the output becomes as shown in figure 2c ***** ***** Service Total Average Dining Lodging Conference 425.0 425.00 Parking 220.8 44.16 544.0 181.35 0.0 0,00 Figure 2e Output Sample2 exe2 Benjamin Bayer:Dining:26.5 English Joyce A:Lodging:120.14 Zalaya:Lodging:173.6 Chung-cha kim:Conference:425 Davidson:Dining:15.6 Rohan Panchal:Dining:36.9 Barbara Benson:Dining:45.8 Smith John B:Lodging:250.3 Wong, Fanklin:Dining:96 (Hotel text file )
Expert Solution
steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY