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 220.8 44.16 544.0 181.35 Parking 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 )

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

Use count controlled 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 4 steps with 4 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
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.
Similar questions
  • SEE MORE QUESTIONS
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