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 working_time.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

Respuesta :

Answer:

total_hours = 0

total_minutes = 0

employees = int(input("How many employees there are? "))

for e in range(employees):

   hours = int(input("Enter the hours: "))

   minutes = int(input("Enter the minutes: "))

   

   total_hours += hours

   total_minutes += minutes

       

   if total_minutes >= 60:

       total_hours += int(total_minutes / 60)

       total_minutes = total_minutes % 60

print("Total time: " + str(total_hours) + " hours " + str(total_minutes) + " minutes")

Explanation:

Initialize the  total_hours and total_minutes as 0

Ask the user to enter the number of employees

Create a for loop that iterates for each employee. Inside the loop, ask the user to enter the hours and minutes. Add the hours to total_hours (cumulative sum) and add the minutes to total_minutes (cumulative sum). If the total_minutes is greater than or equal to 60, get the number of hours in the total_minutes, divide total_minutes by 60 and get the integer part. Also, set the total_minutes to remainder of the minutes from 60

When the loop is done, print the hours and minutes as requested