Ask Question
13 August, 04:26

Complete the function ending_time that determines the final clock time after a task has been completed. The function takes three arguments that provide the current time of day, as well as the total time in seconds that it will take to complete the task: hour: the current hour of the day (0 - 23) minute: the current minute of the day (0 - 59) second: the current second of the day (0 - 59) time_taken: the number of seconds it will take to complete the task (greater than 0) Assume all inputs are valid. time_taken can be arbitrarily large! As an example, consider the test case: 2, 59, 40, 22. This means that the current hour is 2, the current minute is 59, the current second is 40, and the time to complete the task is 22 seconds. So the first three function arguments represent the time 2:59:40 am.

+5
Answers (1)
  1. 13 August, 04:36
    0
    def ending_time (hour, minutes, seconds, work_time) : if ((seconds + work_time) / / 60 > 0) : minutes = minutes + (seconds + work_time) / / 60 seconds = (seconds + work_time) % 60 if (minutes / / 60 > 0) : hour = hour + (minutes / / 60) minutes = minutes % 60 else: seconds = seconds + work_time return str (hour) + ":" + str (minutes) + ":" + str (seconds) print (ending_time (2,30,59, 12000))

    Explanation:

    The solution code is written in Python 3.

    Firstly create a function ending_time that takes the four required input parameters.

    Next, create an if statement to check if the numerator of (seconds + work_times) divided by 60 is over zero. If so, increment the minute and reassign the remainder of the seconds to the variable (Line 2-4).

    Next, create another if statement again to check if the numerator of (current minutes) divided by 60 is over zero, if so increment the hour and reassign the remainder of the minutes to the variable (Line 6-8)

    Otherwise, just simply add the work_time to the current seconds

    At last return the time output string (Line 12).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Complete the function ending_time that determines the final clock time after a task has been completed. The function takes three arguments ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers