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.

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter3: Performing Calculations With Formulas And Functions
Section: Chapter Questions
Problem 3.10CP
icon
Related questions
Topic Video
Question
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
Dr., Julia Scott, 141518
Prof.,Joan Stewart, 111673
Mr.,Ali Al-shukaili,122311
Prof., Sana Al-Abri, 131673
Prof.,Joan Stewart
Dr., Fadi A1-Rasdhi, 153790
Ms., Salwa Al-Youssfi, 111675
Dr., Daniel Cooper, 153790
Dr., Lillian Brown, unknown
Dr. :Benjamin Russell:117642
Dr., Daniel Cooper, 153790
Dr., Lillian Brown, 67251
Dr., Benjamin Russell,117642
Prof., Patrick Bailey, 72305
Dr., Ralph Flores, 118457
Dr., Douglas Flores, 181793
Dr., Lillian Brown, 67251
Figure 1.b: A sample of the text file 'employees.txt"
Figure 1.a: A sample of the text file
'employees.txt' without errors
Figure 1.e: A sample of the text file
"employees.txt' including 3 invalid records
including 2 records with incorrect titles
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
Salarles per category
Salaries per category:
....... ........
**...
................
Nane
Salary
Salary
Name
Salary
Prof.
Joan Stevart
111673.00
Prof.
Patrick telley
72s.00
Sana Al-Abri
131673.00
Dr.
*****
The average salary ef 2 Prof. is: 91989.00
Julia Scott
Daniel Cooper
..
141518.00
The average salary of 1 Prof. is: 131673.00
***** .
153790.00
..
Julia Scett
Daniel Ceeper
Lllan Bron
Benjanin Russell
Ralph Fleres
Douglas Fleres
Dr.
-... ... .. . ..
141518.0
15370.00
67251.00
15379.00
The average salary of 2 Dr. is: 147654.00
67251.00
117642.00
Fadi Al-Raschi
Lillian Bron
. .... ...
118457.00
181793.00
The number of records having incorrect title is e
The number of invalid records is 3
The average salary of 2 Dr. is: 110520. se
The nuber ef records having incorrect title is 2
The nuber ef invalid records is
The average salary of 6 Dr, is: 130075.17
The nuber of records having incorrect title is .
The nuber of invalid recerds is e
Figure 2.b: The output of the program
Figure 2.e: The output of the program
Figure 2.a: The output of the program
related to input file of figure L.a
related to input file of figure 1.b
related to input file of figure L.e
Your program should handle the following error situations.
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
a.
title.
c. Invalid data (such as incorrect separator, less than 3 attributes, non-numerical salary, ...), in which case
increment the number of invalid records.
Transcribed Image Text: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 Dr., Julia Scott, 141518 Prof.,Joan Stewart, 111673 Mr.,Ali Al-shukaili,122311 Prof., Sana Al-Abri, 131673 Prof.,Joan Stewart Dr., Fadi A1-Rasdhi, 153790 Ms., Salwa Al-Youssfi, 111675 Dr., Daniel Cooper, 153790 Dr., Lillian Brown, unknown Dr. :Benjamin Russell:117642 Dr., Daniel Cooper, 153790 Dr., Lillian Brown, 67251 Dr., Benjamin Russell,117642 Prof., Patrick Bailey, 72305 Dr., Ralph Flores, 118457 Dr., Douglas Flores, 181793 Dr., Lillian Brown, 67251 Figure 1.b: A sample of the text file 'employees.txt" Figure 1.a: A sample of the text file 'employees.txt' without errors Figure 1.e: A sample of the text file "employees.txt' including 3 invalid records including 2 records with incorrect titles 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 Salarles per category Salaries per category: ....... ........ **... ................ Nane Salary Salary Name Salary Prof. Joan Stevart 111673.00 Prof. Patrick telley 72s.00 Sana Al-Abri 131673.00 Dr. ***** The average salary ef 2 Prof. is: 91989.00 Julia Scott Daniel Cooper .. 141518.00 The average salary of 1 Prof. is: 131673.00 ***** . 153790.00 .. Julia Scett Daniel Ceeper Lllan Bron Benjanin Russell Ralph Fleres Douglas Fleres Dr. -... ... .. . .. 141518.0 15370.00 67251.00 15379.00 The average salary of 2 Dr. is: 147654.00 67251.00 117642.00 Fadi Al-Raschi Lillian Bron . .... ... 118457.00 181793.00 The number of records having incorrect title is e The number of invalid records is 3 The average salary of 2 Dr. is: 110520. se The nuber ef records having incorrect title is 2 The nuber ef invalid records is The average salary of 6 Dr, is: 130075.17 The nuber of records having incorrect title is . The nuber of invalid recerds is e Figure 2.b: The output of the program Figure 2.e: The output of the program Figure 2.a: The output of the program related to input file of figure L.a related to input file of figure 1.b related to input file of figure L.e Your program should handle the following error situations. 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 a. title. c. Invalid data (such as incorrect separator, less than 3 attributes, non-numerical salary, ...), in which case increment the number of invalid records.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 9 images

Blurred answer
Knowledge Booster
Instruction Format
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
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage