In: Computer Science
A company needs calculating the total working time of
employees in a team. You are going to help to write a program that
totals the working time in hours and minutes. You
should name your program as workingTime.py.
Your program should first ask the user how many employees there are
on the team. You may assume the value entered will not be negative,
but it could be zero. Your program will now be controlled by a loop
that asks for, and adds, the hours and minutes for each employee.
Of course the minutes will frequently add up to more than an hour,
but you should not report a total time such as 24 hours 77 minutes
for example (or worse, 18 hours 377 minutes). Instead you should
report the total time as 25 hours 17 minutes . On the other hand,
if the total number of hours is 24 or greater you should not report
the time in days, hours and minutes. Hours and minutes
are all that are to be reported.
While you may assume that all of the hours and minutes entered by the user will be nonnegative, a time may be entered with minutes that exceed 60. Your program should be able to handle this and still report the total correctly. For example, 5 hours, 65 minutes and 3 hours, 88 minutes should add up to 10 hours, 33 minutes. Consequently for a given team we should see output such as:
Total time: 29 hours 18 minutes
Note: 1. The number 29 and 18
is calculated based on the user’s input.
2. If you already know about conditionals, you may not use them in
this program.
In part II, the company needs to calculate the total working time for employees from all teams in days, hours, and minutes. Users of the program report that they do not like having to start the program over and over to process multiple teams, so we are going to fix that complaint.
Add code to first ask how many teams are to be processed (you may assume the value entered is non-negative). Use this number to determine how many times the program will go through one loop (known as an outer loop) that contains within it the code from part 1. Since the loop from the code of part 1 will now lie within the loop you are developing for this part of the assignment, it is known as the inner loop. At the end of each pass of the outer loop your program should identify the team being processed as Team1, Team2, etc. and then report the total time of that Team. Thus we may see output such as:
Team1 Total time: 29 hours 18 minutes
Team2 Total time: 27 hours 49 minutes
Team3 Total time: 15 hours 1 minutes
Finally, add code to output the total time of all of the teams entered. Thus, the last line of output may be: Total time of all teams: 3 days 0 hours 8 minutes Note that the total time for all teams should display the number of days, hours, and minutes.
If you already know about conditionals, you may not use them in this program.
If you have any doubts, please give me comment...
teams_work_hours = []
no_teams = int(input("Enter How many teams:"))
for team in range(1, no_teams+1):
totalMins = 0
no_emps = int(input("Enter how many employees there are on the team-"+str(team)+": "))
for emp in range(1, no_emps+1):
hours = int(input("Enter how many hours worked for employee "+str(emp)+": "))
mins = int(input("Enter how many minutes worked for employee "+str(emp)+": "))
totalMins += hours*60 + mins
teams_work_hours.append(totalMins)
teamNo = 1
totalTime = 0
for w_hours in teams_work_hours:
print("Team"+str(teamNo)+" Total time:{0} hours {1} minutes".format((w_hours//60), (w_hours%60)))
totalTime += w_hours
teamNo += 1
print("Total time of all teams:{0} days {1} hours {2} minutes".format((totalTime//1440), ((totalTime%1440)//60),((totalTime%1440)%60)))