At Westonci.ca, we connect you with the best answers from a community of experienced and knowledgeable individuals. Discover the answers you need from a community of experts ready to help you with their knowledge and experience in various fields. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

Write a program to take in a time-of-day on the command-line as 3 integers representing hours, minutes, and seconds, along with a 4th argument of additional seconds. Recompute the time by adding the additional seconds to the time in the first three command-line arguments. Output: - display the original time given on the command-line - display the newly computed time Example: python computeTime.py 5 59 32 30 Initial time: 5:59:32 Computed time: 6:00:02 {6:0:2 would also be acceptable}

Sagot :

Answer:

In Python:

hh = int(input("Hour: ")) * 3600

mm = int(input("Minutes: ")) * 60

ss = int(input("Seconds: "))

seconds = int(input("Additional Seconds: "))

time = hh+ mm + ss + seconds

hh =  int(time/3600)

time = time - hh * 3600

mm = int(time/60)

ss = time - mm * 60

while(hh>24):

   hh = hh - 24

print(str(hh)+" : "+str(mm)+" : "+str(ss))

Explanation:

We start by getting the time of the day. This is done using the next three lines

hh = int(input("Hour: ")) * 3600

mm = int(input("Minutes: ")) * 60

ss = int(input("Seconds: "))

Then, we get the additional seconds

seconds = int(input("Additional Seconds: "))

The new time is then calculated (in seconds)

time = hh+ mm + ss + seconds

This line extracts the hours from the calculated time (in seconds)

hh =  int(time/3600)

time = time - hh * 3600

This line extracts the minutes from the calculated time (in seconds)

mm = int(time/60)

This line gets the remaining seconds

ss = time - mm * 60

The following iteration ensures that the hour is less than 24

while(hh>24):

   hh = hh - 24

This prints the calculated time

print(str(hh)+" : "+str(mm)+" : "+str(ss))

Thank you for choosing our service. We're dedicated to providing the best answers for all your questions. Visit us again. Thanks for using our service. We're always here to provide accurate and up-to-date answers to all your queries. Get the answers you need at Westonci.ca. Stay informed with our latest expert advice.