In: Computer Science
. 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 teststhe 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.
Program code in to1.py:
def pieces_produced():
time=int(input("\nTime of the day:"))
workers=int(input("Number of workers:"))
if(workers<0):
print("Number of workers
should be non-negative value....")
pieces=-1
else:
if(time>=6 and
time<10):
pieces=30*workers
elif(time>=10 and
time<14):
pieces=40*workers
elif(time>=14 and
time<=18):
pieces=35*workers
else:
pieces=-1
print("Time is not valid...It should be between(6-18)")
return pieces
for i in range(3):
value=pieces_produced();
if(value==-1):
print("Can not perform calculation.")
else:
print("The total number of pieces produced:",value)
Data in testing.txt:
>>>
= RESTART: C:/Users/Sappati
Praveena/AppData/Local/Programs/Python/Python38-32/to1.py
Time of the day:18
Number of workers:23
The total number of pieces produced: 805
Time of the day:5
Number of workers:-3
Number of workers should be non-negative value....
Can not perform calculation.
Time of the day:20
Number of workers:5
Time is not valid...It should be between(6-18)
Can not perform calculation.
>>>