Advertisements
Advertisements
प्रश्न
Write a program to find difference between two times with hours, minutes and seconds.
कोड लेखन
Advertisements
उत्तर
Convert both times into seconds, find the difference, and convert the result back into hours, minutes and seconds.
hours1 = int(input("Enter first time hours: "))
minutes1 = int(input("Enter first time minutes: "))
seconds1 = int(input("Enter first time seconds: "))
hours2 = int(input("Enter second time hours: "))
minutes2 = int(input("Enter second time minutes: "))
seconds2 = int(input("Enter second time seconds: "))
time1 = hours1 * 3600 + minutes1 * 60 + seconds1
time2 = hours2 * 3600 + minutes2 * 60 + seconds2
difference = abs(time1 - time2)
hours = difference // 3600
difference %= 3600
minutes = difference // 60
seconds = difference % 60
print("Difference =", hours, "hours", minutes, "minutes", seconds, "seconds")
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
