Problem Definition You are provided with a text file (employees.txt) containing a number of text lines. Each line contains a record of one employee. Each record has three attributes: Title: string, Prof. (Professor) or Dr. (Doctor). First and Last names: string. Salary: float number. The attributes are separated by the character (','). Figure 1.a, 1.b, and 1.c show a sample of employees.txt files. Dr., Julia Scott, 141518 Prof.,Joan Stewart Dr., Julia Scott, 141518 Prof., Joan Stewart, 111673 Dr., Daniel Cooper, 153790 Dr., Lillian Brown, 67251 Dr., Benjamin Russell, 117642 Prof., Patrick Bailey, 72305 Dr., Ralph Flores, 118457 Dr., Douglas Flores, 181793 Mr.,Ali Al-Shukaili,122311 Prof., Sana Al-Abri, 131673 Dr., Fadi A1-Rasdhi, 153790 Ms., Salwa A1-Youssfi, 111675 Dr., Lillian Brown, 67251 Dr., Daniel Cooper, 153790 Dr.,Lillian Brown, unknown Dr. : Benjamin Russell:117642 Figure 1.b: A sample of the text file 'employees.tNt" including 2 records with incorrect titles Figure L.e: A sample of the text file employees.txt' including 3 invalid records Figure L.a: A sample of the text file 'emplayees.txt' without errors You are requested to write a Python program that reads the contents of the text file, saves the titles, the names and the salaries of employees in three lists and computes the average salary per title as well as the average for all employees. Your program should display the employees per titles, the number of employees of each title, the average salary of each title, the average for all employees, as well as the number of records with invalid title, and the number of invalid record as shown in Figure 2.a, 2.b, and 2.c: Salaries per category Salaries per category Salaries per category: ..... Salary Name Sely Name Salary Prof. Joan Stevart Patrick talley Pref. Sana Al-Ari The average alary ef Prof. . Julia Scott 141518.00 The average salary of 1 Prof. Is 11673.00 Daniel Cooper 153790.00 Julla Sett Daniel Coeper Llan Bron tenjanin ussell Ralah Fleres Deuglas Fleres 141S.0 Fadi Al-Raschi Llian tron 153P0.00 67251.00 The average salary of 2 Dr. is: 147654.00 112.00 The average salary of a . 1es.se The number of records having incorrect title is o The number of invalid records is 3 The average salary etr. s.1 The nuber of records having incorrect title is The nuter ef invalid recores is The nuber of records having incorrect title is. The nuber of invalid recerds ise Figure 2.a: The output of the program related to input file of figure La Figure 2.b: The output of the program related to input file of figure L.b Figure 2.e: The output of the program related to input file of figure L.e Your program should handle the following error situations. a. File employees.txt not found, in which case an adequate error message should be displayed. b. Incorrect title (different from 'Prof.' or 'Dr.'), in which case increment the number of records having incorrect title. c. Invalid data (such as incorrect separator, less than 3 attributes, non-numerical salary, ...), in which case increment the number of invalid records.
Problem Definition You are provided with a text file (employees.txt) containing a number of text lines. Each line contains a record of one employee. Each record has three attributes: Title: string, Prof. (Professor) or Dr. (Doctor). First and Last names: string. Salary: float number. The attributes are separated by the character (','). Figure 1.a, 1.b, and 1.c show a sample of employees.txt files. Dr., Julia Scott, 141518 Prof.,Joan Stewart Dr., Julia Scott, 141518 Prof., Joan Stewart, 111673 Dr., Daniel Cooper, 153790 Dr., Lillian Brown, 67251 Dr., Benjamin Russell, 117642 Prof., Patrick Bailey, 72305 Dr., Ralph Flores, 118457 Dr., Douglas Flores, 181793 Mr.,Ali Al-Shukaili,122311 Prof., Sana Al-Abri, 131673 Dr., Fadi A1-Rasdhi, 153790 Ms., Salwa A1-Youssfi, 111675 Dr., Lillian Brown, 67251 Dr., Daniel Cooper, 153790 Dr.,Lillian Brown, unknown Dr. : Benjamin Russell:117642 Figure 1.b: A sample of the text file 'employees.tNt" including 2 records with incorrect titles Figure L.e: A sample of the text file employees.txt' including 3 invalid records Figure L.a: A sample of the text file 'emplayees.txt' without errors You are requested to write a Python program that reads the contents of the text file, saves the titles, the names and the salaries of employees in three lists and computes the average salary per title as well as the average for all employees. Your program should display the employees per titles, the number of employees of each title, the average salary of each title, the average for all employees, as well as the number of records with invalid title, and the number of invalid record as shown in Figure 2.a, 2.b, and 2.c: Salaries per category Salaries per category Salaries per category: ..... Salary Name Sely Name Salary Prof. Joan Stevart Patrick talley Pref. Sana Al-Ari The average alary ef Prof. . Julia Scott 141518.00 The average salary of 1 Prof. Is 11673.00 Daniel Cooper 153790.00 Julla Sett Daniel Coeper Llan Bron tenjanin ussell Ralah Fleres Deuglas Fleres 141S.0 Fadi Al-Raschi Llian tron 153P0.00 67251.00 The average salary of 2 Dr. is: 147654.00 112.00 The average salary of a . 1es.se The number of records having incorrect title is o The number of invalid records is 3 The average salary etr. s.1 The nuber of records having incorrect title is The nuter ef invalid recores is The nuber of records having incorrect title is. The nuber of invalid recerds ise Figure 2.a: The output of the program related to input file of figure La Figure 2.b: The output of the program related to input file of figure L.b Figure 2.e: The output of the program related to input file of figure L.e Your program should handle the following error situations. a. File employees.txt not found, in which case an adequate error message should be displayed. b. Incorrect title (different from 'Prof.' or 'Dr.'), in which case increment the number of records having incorrect title. c. Invalid data (such as incorrect separator, less than 3 attributes, non-numerical salary, ...), in which case increment the number of invalid records.
Chapter3: Performing Calculations With Formulas And Functions
Section: Chapter Questions
Problem 3.10CP
Related questions
Topic Video
Question
Expert Solution
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 4 steps with 9 images
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
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage