In: Computer Science
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.
The program for above question is given below with comments and output screenshots......
Explanation is in the comments ....
However i didn't include the last hours of time slot that means if time is 10am then it won't go in 6am to 10am slot...but it will go in 10am to 2pm slot .....and i guess that was expected..since the hour begins at 10am
I hope it works for you :)!!!!!!!!!!!!
ask for any help if needed !
*********************Program***************************
t01.py
import functions #import functions.py module
hour=int(input("Time of the Day: ")) #taking hour from
user
noOfWorkers=int(input("Number of Workers: ")) #taking numberof
workers from user
pieces=functions.pieces_produced(hour,noOfWorkers) #calling the
pieces_produced() function in functions module
#and storing return value in pieces variable
if pieces!=-1: #if return value is not -1 then print
pieces
print("The Total number of pieces produced: ",pieces)
else: #ootherwise(if return value is -1) print below
statement
print("Can not perform the calculation")
functions.py
def pieces_produced(hour,noOfWorkers): #function definition with 2
parameters
if hour>=18 or noOfWorkers<=0:
return -1 #if houe or number of workers is invalid then retun
-1
if hour>=6 and hour<10: #if hour is between 6am to 10am
return 30*noOfWorkers #return no of pieces produced that hour
if hour>=10 and hour<14: #if hour is between 10am to
2pm
return 40*noOfWorkers #return no of pieces produced
if hour>=14 and hour<18: #if hour is between 2pm to 6pm
return 35*noOfWorkers #return no of pieces produced
***********************Output***************************
THANK YOU!! PLEASE VOTE