Question

In: Computer Science

Suppose we have an input file that contains information about how many hours each employee of...

Suppose we have an input file that contains information about how many hours each employee of a company has worked. The file looks like the following (Employee's name, Hours): John 6.5 9.5 7.25 9 8.55 Oscar 12.5 13.5 14 16 18.75 Judith 7 7 7 ••• Construct a program that reads this file and calculates the total number of hours worked by each individual. Make sure that the program handles each specific exception that could occur.'

python

Solutions

Expert Solution

Short Summary:

  • Implemented the program in Python
  • PFB the source code and output

**************Please do upvote to appreciate our time. Thank you!******************

Source Code:

import sys

# Using readlines()
file1 = open('myfile.txt', 'r')
Lines = file1.readlines()
  
# Strips the newline character
try:
for line in Lines:
list1 = line.split()
list2 = list1[1:len(list1)]
count=0
for i in list2:
hour=float(i)
count=count+ hour
print("Name:",list1[0],", Hours worked:",count)
except ValueError:
print("Hours are not in number format")
except:
print("Unexpected error:", sys.exc_info()[0])

Code Screenshot:

Output:


**************Please do upvote to appreciate our time. Thank you!******************


Related Solutions

suppose that the reservoir contains 1.5L of 2.0M K2PO4. For how many hours can the reservoir...
suppose that the reservoir contains 1.5L of 2.0M K2PO4. For how many hours can the reservoir provide 20mM KOH at a flow rate of 1.0 ml/min if 75% consumption of K+ in the reservoir is feasible
The tbl_employee contains information about the employee and its department, and it contains the following fields...
The tbl_employee contains information about the employee and its department, and it contains the following fields (it is possible to also include other missing fields): employee_id, employee_gender ,employee_salary, employee_annual_sallary, department_name, department_location, department head. Make use of the database normalization skills learned to normalize a database to the third normalization form. Organize the columns and tables to reduce data redundancy and arrange attributes based on the relationships. Provide a screen shot of the database design before the normalization. Create a heading...
Suppose we have the following information on the examination scores and weekly employment hours of eight...
Suppose we have the following information on the examination scores and weekly employment hours of eight students: Exam Score      Employment Hours       80                           10       80                           5       68                           15       95                           5       75                           21       60                           40       90                           0     100                           0 Assuming Exam Score is the dependent variable (Y) and Employment Hours is the independent variable (X), calculate the simple linear regression equation by hand. Using this, test to see whether the slope on X is...
[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
2) The file ‘Energy’ contains the per capita energy consumption (in kilowatt-hours), for each of the...
2) The file ‘Energy’ contains the per capita energy consumption (in kilowatt-hours), for each of the 50 states and the District of Columbia during a recent year. a) Compute the mean, variance, and standard deviation for the population. b) What proportion of these states has per capita energy consumption within + or – 1 standard deviation of the mean, within + or – 2 standard deviations of the mean, and within + or – 3 standard deviations of the mean?...
Suppose we conduct a study with 100 participants to estimate how many hours students sleep and...
Suppose we conduct a study with 100 participants to estimate how many hours students sleep and find an average of 8 and a confidence interval that ranges from 5 to 11. What is the margin of error?
C++ There is a file, called EmployeeInfo.txt, that contains information about company employees work for a...
C++ There is a file, called EmployeeInfo.txt, that contains information about company employees work for a week. You will write a program that reads the info from the file, and produces an output file called EmployeePay.txt with information about the employees pay amount for that week. Details: The input file is called EmployeeInfo.txt There are 4 lines of input Each line has the same form Last Name, first Name, hours worked, pay rate, tax percentage, extra deductions Example: John Doe...
Suppose we have a sequential ordered file of 200,000 records, where each record is 200 bytes....
Suppose we have a sequential ordered file of 200,000 records, where each record is 200 bytes. Assume blocksize = 2048 bytes (10 records per block), average seek time = 10 ms, average rotational delay = 8.3 ms, and block transfer time = 0.8 ms. Suppose we want to make X independent random record reads from the file. This could be done in two different approaches. read the entire file once and look for the X records of interest use a...
Done in c++ Read this file one time to determine how many records it contains. Be...
Done in c++ Read this file one time to determine how many records it contains. Be sure to check for a successful file open here. Close the file. Allocate memory dynamically to store the data from step 1. This dynamically allocated memory should be for an array of strings. The array size should be exactly the number of records from step 1. Reopen the file and read it a second time, storing each record into the array of strings from...
Computing A Raise File Salary.java contains most of a program that takes as input an employee’s...
Computing A Raise File Salary.java contains most of a program that takes as input an employee’s salary and a rating of the employee’s performance and computes the raise for the employee. This is similar to question #3 in the pre-lab, except that the performance rating here is being entered as a String—the three possible ratings are “Excellent”, “Good”, and “Poor”. As in the pre-lab, an employee who is rated excellent will receive a 6% raise, one rated good will receive...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT