Question

In: Computer Science

A manufacturing company measured the productivity of its workers and found that: between the hours of...

  1. A manufacturing company measured the productivity of its workers and found that:
    • between the hours of 6am and 10am they could produce 30 pieces/hour/worker
    • between 10am and 2pm they could produce 40 pieces/hour/worker
    • between 2pm and 6pm they could produce 35 pieces/hour/worker.

Write a function pieces_produced takes a number that represents a starting hour between 6am and 6pm, in twenty-four hour format (between 0 and 23), along with the number of workers and returns a number that represents the total number of pieces produced during that hour. If the user enters an invalid hour or number of workers, the function should return -1. Save the function in a PyDev library module named functions.py

Write a testing program named t01.py that tests the function by asking the user to enter hours and number of workers and prints the total number of pieces produced.

A sample run:

Time of the day: 6 Number of workers: 10

The total number of pieces produced:300

Or

Time of the day: 35 Number of workers: 10

Can not perform the calculation

  • test your program with 3 different data than the examples, you may assume that the user will only enter numbers.
  • Copy the results to testing.txt.

Solutions

Expert Solution

Below is the code in Python 3 for the requirements mentioned in the question. In our program below we have assumed that the starting point is INCLUSIVE in the range but finish point is EXCLUSIVE which means that for range 6 am to 10 am, 6 am is in the range and 10 am is not. This we have to do otherwise we cannot make a decision and we made this decision because as in the example they have given time = 6am and performed caculation for that, which means it is inlusive. Sample text file as mentioned in the question is attached below. Also attached screenshots of three examples different from the examples in the question.

Note:- We have used time as invalid if it is outside the range mentioned in the question(6am to 6pm, where 6pm is exclusive) and number of workers is invalid if they are less than or equal to zero.

# function to return the pieces produced for valid time and workers, otherwise return -1. 
def pieces_produced(hour, workers):
    pieces = 0
    if(workers > 0):
        if(hour >= 6 and hour < 10):
            pieces = workers * 30
        
        elif(hour >= 10 and hour < 14):
            pieces = workers * 40
            
        elif(hour >= 14 and hour < 18):
            pieces = workers * 35
            
        else:
            return -1
    
    else:
        return -1
    
    return pieces
    

time = input("Enter time of the day: ")
worker_cnt = input("Enter number of workers: ")

# calling function to calculate pieces produced for a given range.
result = pieces_produced(int(time), int(worker_cnt))

# opening file in append mode which means that result will be appended to existing file.
outF = open("testing.txt", "a")

# below condition will get hit if either time or number of workers is invalid.
if(result == -1):
    outF.write("Can not perform the calculation for time = {} and workers = {}".format(time, worker_cnt))
    outF.write("\n")
    print("Can not perform the calculation")


# below condition will get hit if both inputs are valid.    
else:
    outF.write("The total number of pieces produced for time = {} and workers = {}: {}".format(time, worker_cnt, result))
    outF.write("\n")
    print("The total number of pieces produced: {}".format(result))

Sample File:-

We have created a file in such a way that every time you write to the file, new result will get written to the existing file in the new line. For that we have open the file in "a" mode , which is append mode.

Sample Output 1:-

Since 15 is in the range 2 pm to 6 pm, total pieces that could be produced = 35 * 15 = 525 {because for this range output is 35 pieces/hour/worker} and workers equals 15.

Sample Output 2:-

Time of the day is invalid as it is not in any of the ranges mentioned in the question.

Sample Output 3:-

Since 15 is in the range 10 am to 2 pm, total pieces that could be produced = 40 * 30 = 1200 {because for this range output is 40 pieces/hour/worker} and workers equals 30.


Related Solutions

. A manufacturing company measured the productivity of its workers and found that: • between the...
. A manufacturing company measured the productivity of its workers and found that: • between the hours of 6am and 10am they could produce 30 pieces/hour/worker • between 10am and 2pm they could produce 40 pieces/hour/worker • between 2pm and 6pm they could produce 35 pieces/hour/worker. Write a function pieces_produced takes a number that represents a starting hour between 6am and 6pm, in twenty-four hour format (between 0 and 23), along with the number of workers and returns a number...
1. A manufacturing company measured the productivity of its workers and found that: • between the...
1. A manufacturing company measured the productivity of its workers and found that: • between the hours of 6am and 10am they could produce 30 pieces/hour/worker • between 10am and 2pm they could produce 40 pieces/hour/worker • between 2pm and 6pm they could produce 35 pieces/hour/worker. Write a function pieces_produced takes a number that represents a starting hour between 6am and 6pm, in twenty-four hour format (between 0 and 23), along with the number of workers and returns a number...
The data in this file are the differences in the productivity of workers measured before and...
The data in this file are the differences in the productivity of workers measured before and after they undertake a training program. x 3.483286 0.502139 1.182506 -0.78977 -1.23055 0.050956 -0.55935 -0.44297 -0.28723 -2.20755 -1.29574 -2.37856 1.590792 -1.07265 -0.51803 0.88382 -1.20074 -0.37303 0.046192 0.178191 3.011939 0.370306 -1.16088 0.896363 0.921949 -0.79235 -0.65858 1.442165 1.291734 -1.19235 0.77025 0.130772 0.170839 0.424066 0.144973 -2.14435 0.925843 2.61098 1.358568 1.635042 -0.39504 0.493437 -0.12331 -1.35487 0.336548 -2.47492 -2.26872 -0.25936 -0.54652 1.104589 -0.39521 3.072957 1.835252 -1.30094 2.040434 2.496305 0.567188...
Roberta wants to compare productivity, as measured by the number of customers served, among three workers....
Roberta wants to compare productivity, as measured by the number of customers served, among three workers. The number of customers served by each worker is shown below. Edward Cathy Brad 55 66 55 59 76 51 66 67 46 60 71 48 Is there a difference in the number of customers served? The level of significance is 0.01. Show all the five steps of the hypothesis testing.
A manufacturing company for car batteries uses lead in its manufacturing process. Workers are encouraged to...
A manufacturing company for car batteries uses lead in its manufacturing process. Workers are encouraged to shower, shampoo, and change             clothes before going home to eliminate the transfer of lead to their children, but there is still concern that children are being exposed by their parents. A study is carried out to determine whether workers carry lead dust home. 33 of the workers children were selected as subjects, and a blood tests for each child determines the level of...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts each week. Management is interested in whether there is a difference in the number of units produced when the employees work on various shifts. A sample of five workers is selected and their output recorded on each shift. At the 0.05 significance level, can we conclude there is a difference in the mean production rate by shift or by employee? Units Produced Employee Day...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts each week. Management is interested in whether there is a difference in the number of units produced when the employees work on various shifts. A sample of five workers is selected and their output recorded on each shift. At the 0.01 significance level, can we conclude there is a difference in the mean production rate by shift or by employee? Units Produced Employee Day...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts each week. Management is interested in whether there is a difference in the number of units produced when the employees work on various shifts. A sample of five workers is selected and their output recorded on each shift. At the 0.05 significance level, can we conclude there is a difference in the mean production rate by shift or by employee? Units Produced Employee Day...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts...
Chapin Manufacturing Company operates 24 hours a day, five days a week. The workers rotate shifts each week. Management is interested in whether there is a difference in the number of units produced when the employees work on various shifts. A sample of five workers is selected and their output recorded on each shift. At the 0.01 significance level, can we conclude there is a difference in the mean production rate by shift or by employee? Units Produced Employee Day...
How is labor productivity measured? What is the trend in labor productivity? How is labor productivity...
How is labor productivity measured? What is the trend in labor productivity? How is labor productivity related to economic growth? What helps and what hurts labor productivity? Can labor productivity keep growing forever?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT